fix: do not allow duplicit keys

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-12 12:20:24 +02:00
parent 32ec9e9866
commit 705d5cfa17
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 9 additions and 1 deletions

View file

@ -146,7 +146,12 @@ class Node(Generic[T]):
while new_node and (missing or new_node.value != value): while new_node and (missing or new_node.value != value):
node = new_node 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 return node

View file

@ -82,6 +82,9 @@ class RankedTree(Generic[T]):
return return
parent = Node.find_parent_node(value, self.root) parent = Node.find_parent_node(value, self.root)
if not parent:
return
inserted_node.parent = parent inserted_node.parent = parent
if value < parent.value: if value < parent.value: