mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Merge pull request #5629 from smercer10/fix-rbtree-find-or-insert
Fix rbtree.find_or_insert
This commit is contained in:
@@ -128,9 +128,9 @@ find_value :: proc(t: ^$T/Tree($Key, $Value), key: Key) -> (value: Value, ok: bo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// find_or_insert attempts to insert the value into the tree, and returns
|
// find_or_insert attempts to insert the key-value pair into the tree, and returns
|
||||||
// the node, a boolean indicating if the value was inserted, and the
|
// the node, a boolean indicating if a new node was inserted, and the
|
||||||
// node allocator error if relevant. If the value is already present, the existing node is updated.
|
// 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) {
|
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
|
n_ptr := &t._root
|
||||||
for n_ptr^ != nil {
|
for n_ptr^ != nil {
|
||||||
@@ -141,6 +141,7 @@ find_or_insert :: proc(t: ^$T/Tree($Key, $Value), key: Key, value: Value) -> (n:
|
|||||||
case .Greater:
|
case .Greater:
|
||||||
n_ptr = &n._right
|
n_ptr = &n._right
|
||||||
case .Equal:
|
case .Equal:
|
||||||
|
n.value = value
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user