Skip to content

Commit

Permalink
add find
Browse files Browse the repository at this point in the history
  • Loading branch information
pastilhas committed Oct 12, 2024
1 parent 2daab3d commit b3a1ecc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/rbtree.v
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,18 @@ fn (mut t RBTree[T]) delete[T](val T) bool {
fn (mut t RBTree[T]) delete_fixup[T](node &Node[T]) {
}

fn (mut t RBTree[T]) find[T](val T) ?&Node[T] {
fn (mut t RBTree[T]) find[T](val T) ?T {
for p := t.root; unsafe { p != 0 }; {
c := t.cmp(p.val, val)
if c == 0 {
return p.val
}
p = if c > 0 {
p.left
} else {
p.right
}
}
return none
}

Expand Down

0 comments on commit b3a1ecc

Please sign in to comment.