File tree Expand file tree Collapse file tree 1 file changed +22
-14
lines changed
Expand file tree Collapse file tree 1 file changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -361,22 +361,30 @@ func (t Tree[T]) CoverLCP(item T) (result T, ok bool) {
361361
362362// lcp rec-descent.
363363func (t * Tree [T ]) lcp (n * node [T ], item T ) (result T , ok bool ) {
364- if n == nil {
365- return
366- }
364+ for {
365+ if n == nil {
366+ // stop condition
367+ return
368+ }
367369
368- // fast exit, node has too small max upper interval value (augmented value)
369- if t .cmpRR (item , n .maxUpper .item ) > 0 {
370- return
371- }
370+ // fast exit, node has too small max upper interval value (augmented value)
371+ if t .cmpRR (item , n .maxUpper .item ) > 0 {
372+ // stop condition
373+ return
374+ }
372375
373- switch cmp := t .compare (n .item , item ); {
374- case cmp > 0 :
375- // too big, left rec-descent
376- return t .lcp (n .left , item )
377- case cmp == 0 :
378- // equality is always the shortest containing hull
379- return n .item , true
376+ cmp := t .compare (n .item , item )
377+ if cmp == 0 {
378+ // equality is always the shortest containing hull
379+ return n .item , true
380+ }
381+
382+ if cmp < 0 {
383+ break
384+ }
385+
386+ // item too big, go left
387+ n = n .left
380388 }
381389
382390 // LCP => right backtracking
You can’t perform that action at this time.
0 commit comments