aboutsummaryrefslogtreecommitdiff
path: root/core/container
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-10-08 11:21:34 +0100
committerGitHub <noreply@github.com>2025-10-08 11:21:34 +0100
commitb427e025d737f1e7640fe193a4c852adf934240c (patch)
tree13c83c43e9b13357be13a2bc753eb07f26299c30 /core/container
parent39ace7f5c18bc90ae1cf7318f1aaf3c2b4e76600 (diff)
parent30021e8dac0ff6a9a8ddc023f5a4c3924ebfd7c3 (diff)
Merge pull request #5629 from smercer10/fix-rbtree-find-or-insert
Fix rbtree.find_or_insert
Diffstat (limited to 'core/container')
-rw-r--r--core/container/rbtree/rbtree.odin7
1 files changed, 4 insertions, 3 deletions
diff --git a/core/container/rbtree/rbtree.odin b/core/container/rbtree/rbtree.odin
index 090551367..e9d0d08f4 100644
--- a/core/container/rbtree/rbtree.odin
+++ b/core/container/rbtree/rbtree.odin
@@ -128,9 +128,9 @@ find_value :: proc(t: ^$T/Tree($Key, $Value), key: Key) -> (value: Value, ok: bo
return
}
-// find_or_insert attempts to insert the value into the tree, and returns
-// the node, a boolean indicating if the value was inserted, and the
-// node allocator error if relevant. If the value is already present, the existing node is updated.
+// find_or_insert attempts to insert the key-value pair into the tree, and returns
+// the node, a boolean indicating if a new node was inserted, and the
+// node allocator error if relevant. If the key is already present, the existing node is updated and returned.
find_or_insert :: proc(t: ^$T/Tree($Key, $Value), key: Key, value: Value) -> (n: ^Node(Key, Value), inserted: bool, err: runtime.Allocator_Error) {
n_ptr := &t._root
for n_ptr^ != nil {
@@ -141,6 +141,7 @@ find_or_insert :: proc(t: ^$T/Tree($Key, $Value), key: Key, value: Value) -> (n:
case .Greater:
n_ptr = &n._right
case .Equal:
+ n.value = value
return
}
}