Skip to content

Commit

Permalink
lookup without split() is a pity
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Jan 22, 2023
1 parent b98297c commit cc37554
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions treap.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,23 @@ func (n *node[T]) lcp(item T) (result T, ok bool) {
// now on proper depth in tree
// first try right subtree for shortest containing hull
if n.right != nil {

// rec-descent with n.right
if compare(n.right.item, item) <= 0 {
result, ok = n.right.lcp(item)
if ok {
return result, ok
}
}

// try n.right.left subtree for smallest containing hull
// take this path only if n.right.left.item > t.item (this node)
if n.right.left != nil && compare(n.right.left.item, n.item) > 0 {
// rec-descent with n.right.left
result, ok = n.right.left.lcp(item)
if ok {
return result, ok
} else {
// try n.right.left subtree for smallest containing hull
// take this path only if n.right.left.item > t.item (this node)
if n.right.left != nil && compare(n.right.left.item, n.item) > 0 {
// rec-descent with n.right.left
result, ok = n.right.left.lcp(item)
if ok {
return result, ok
}
}
}

}

// not found in right subtree, try this node
Expand Down

0 comments on commit cc37554

Please sign in to comment.