fix: do not allow duplicit keys
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
32ec9e9866
commit
705d5cfa17
2 changed files with 9 additions and 1 deletions
7
node.py
7
node.py
|
@ -146,7 +146,12 @@ class Node(Generic[T]):
|
|||
|
||||
while new_node and (missing or new_node.value != value):
|
||||
node = new_node
|
||||
new_node = node.left if value < node.value else node.right
|
||||
if value < node.value:
|
||||
new_node = node.left
|
||||
elif node.value < value:
|
||||
new_node = node.right
|
||||
else:
|
||||
return None
|
||||
|
||||
return node
|
||||
|
||||
|
|
|
@ -82,6 +82,9 @@ class RankedTree(Generic[T]):
|
|||
return
|
||||
|
||||
parent = Node.find_parent_node(value, self.root)
|
||||
if not parent:
|
||||
return
|
||||
|
||||
inserted_node.parent = parent
|
||||
|
||||
if value < parent.value:
|
||||
|
|
Loading…
Reference in a new issue