mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 03:40:08 +00:00
Address concerns.
This commit is contained in:
@@ -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
|
// 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
|
// 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.
|
// 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
|
n_ptr := &t._root
|
||||||
for n_ptr^ != nil {
|
for n_ptr^ != nil {
|
||||||
n = n_ptr^
|
n = n_ptr^
|
||||||
@@ -145,11 +145,12 @@ find_or_insert :: proc(t: ^$T/Tree($Key, $Value), key: Key, value: Value) -> (n:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_parent := 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
|
n_ptr^ = n
|
||||||
insert_case1(t, n)
|
insert_case1(t, n)
|
||||||
t._size += 1
|
t._size += 1
|
||||||
return n, true
|
return n, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove removes a node or value from the tree, and returns true iff the
|
// 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 returns a tree iterator in the specified direction.
|
||||||
iterator :: proc "contextless" (t: ^$T/Tree($Key, $Value), direction: Direction) -> Iterator(Key, Value) {
|
iterator :: proc "contextless" (t: ^$T/Tree($Key, $Value), direction: Direction) -> Iterator(Key, Value) {
|
||||||
it: Iterator(Key, Value)
|
it: Iterator(Key, Value)
|
||||||
it._tree = transmute(^Tree(Key, Value))t
|
it._tree = cast(^Tree(Key, Value))t
|
||||||
it._direction = direction
|
it._direction = direction
|
||||||
|
|
||||||
iterator_first(&it)
|
iterator_first(&it)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ test_rbtree_integer :: proc(t: ^testing.T, $Key: typeid, $Value: typeid) {
|
|||||||
v := Value(rand.uint32(&r))
|
v := Value(rand.uint32(&r))
|
||||||
|
|
||||||
existing_node, in_map := inserted_map[k]
|
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")
|
tc.expect(t, in_map != inserted, "insert: inserted should match inverse of map lookup")
|
||||||
if inserted {
|
if inserted {
|
||||||
inserted_map[k] = n
|
inserted_map[k] = n
|
||||||
|
|||||||
Reference in New Issue
Block a user