aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-05-24 13:58:30 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2024-05-24 13:58:30 +0200
commit11e57fd3fd290c1237f33e83f0142b3d98a7e2d9 (patch)
treea74b04c58953c4a63438c61638722aa6f5e15454
parentc43d189a3353637b416571b90cab3bc8aa0aaf87 (diff)
Address concerns.
-rw-r--r--core/container/rbtree/rbtree.odin9
-rw-r--r--tests/core/container/test_core_rbtree.odin2
2 files changed, 6 insertions, 5 deletions
diff --git a/core/container/rbtree/rbtree.odin b/core/container/rbtree/rbtree.odin
index 26cce46b4..8ab131b3b 100644
--- a/core/container/rbtree/rbtree.odin
+++ b/core/container/rbtree/rbtree.odin
@@ -131,7 +131,7 @@ find_value :: proc(t: ^$T/Tree($Key, $Value), key: Key) -> (value: Value, ok: bo
// 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 :: proc(t: ^$T/Tree($Key, $Value), key: Key, value: Value) -> (n: ^Node(Key, Value), inserted: bool) {
+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 {
n = n_ptr^
@@ -145,11 +145,12 @@ find_or_insert :: proc(t: ^$T/Tree($Key, $Value), key: Key, value: Value) -> (n:
}
}
_parent := n
- n = new_clone(Node(Key, Value){key=key, value=value, _parent=_parent, _color=.Red}, t._node_allocator) // or_return
+
+ n = new_clone(Node(Key, Value){key=key, value=value, _parent=_parent, _color=.Red}, t._node_allocator) or_return
n_ptr^ = n
insert_case1(t, n)
t._size += 1
- return n, true
+ return n, true, nil
}
// remove removes a node or value from the tree, and returns true iff the
@@ -208,7 +209,7 @@ remove_node :: proc(t: ^$T/Tree($Key, $Value), node: ^$N/Node(Key, Value), call_
// iterator returns a tree iterator in the specified direction.
iterator :: proc "contextless" (t: ^$T/Tree($Key, $Value), direction: Direction) -> Iterator(Key, Value) {
it: Iterator(Key, Value)
- it._tree = transmute(^Tree(Key, Value))t
+ it._tree = cast(^Tree(Key, Value))t
it._direction = direction
iterator_first(&it)
diff --git a/tests/core/container/test_core_rbtree.odin b/tests/core/container/test_core_rbtree.odin
index 08db3c664..89742b1d0 100644
--- a/tests/core/container/test_core_rbtree.odin
+++ b/tests/core/container/test_core_rbtree.odin
@@ -44,7 +44,7 @@ test_rbtree_integer :: proc(t: ^testing.T, $Key: typeid, $Value: typeid) {
v := Value(rand.uint32(&r))
existing_node, in_map := inserted_map[k]
- n, inserted := rb.find_or_insert(&tree, k, v)
+ n, inserted, _ := rb.find_or_insert(&tree, k, v)
tc.expect(t, in_map != inserted, "insert: inserted should match inverse of map lookup")
if inserted {
inserted_map[k] = n