fix rbtree memory error, check neel

This commit is contained in:
c9s 2021-05-23 01:12:16 +08:00
parent 9c70e36e1b
commit de768296f1

View File

@ -336,14 +336,14 @@ func (tree *RBTree) Rightmost() *RBNode {
}
func (tree *RBTree) RightmostOf(current *RBNode) *RBNode {
for current.Right != Neel {
current = current.Right
}
if current == Neel {
return nil
}
for current.Right != Neel {
current = current.Right
}
return current
}
@ -352,18 +352,22 @@ func (tree *RBTree) Leftmost() *RBNode {
}
func (tree *RBTree) LeftmostOf(current *RBNode) *RBNode {
for current.Left != Neel {
current = current.Left
}
if current == Neel {
return nil
}
for current.Left != Neel {
current = current.Left
}
return current
}
func (tree *RBTree) Successor(current *RBNode) *RBNode {
if current == Neel {
return nil
}
if current.Right != Neel {
return tree.LeftmostOf(current.Right)
}