chore(tree): some small cleanups
parent
bee520a781
commit
ef5037f941
|
@ -1,5 +1,6 @@
|
|||
#include "vieter_tree_internal.h"
|
||||
#include "vieter_tree_node.h"
|
||||
#include "vieter_tree_balancing.h"
|
||||
|
||||
struct vieter_tree {
|
||||
uint64_t size;
|
||||
|
|
|
@ -46,13 +46,6 @@ void vieter_tree_node_set_child(vieter_tree_node *parent,
|
|||
}
|
||||
}
|
||||
|
||||
void vieter_tree_node_replace_with_child(vieter_tree_node *to_replace,
|
||||
vieter_tree_node *replacement) {
|
||||
to_replace->key = replacement->key;
|
||||
to_replace->data = replacement->data;
|
||||
vieter_tree_node_set_children(to_replace, replacement->children);
|
||||
}
|
||||
|
||||
vieter_tree_error vieter_tree_node_insert(vieter_tree_node *root, uint64_t key,
|
||||
void *data) {
|
||||
vieter_tree_node *node = root;
|
||||
|
|
|
@ -20,10 +20,19 @@ typedef struct vieter_tree_node {
|
|||
uint8_t flags;
|
||||
} vieter_tree_node;
|
||||
|
||||
/*
|
||||
* Allocate a new node.
|
||||
*/
|
||||
vieter_tree_node *vieter_tree_node_init();
|
||||
|
||||
/*
|
||||
* Free an allocated node.
|
||||
*/
|
||||
void vieter_tree_node_free(vieter_tree_node *node);
|
||||
|
||||
/*
|
||||
* Insert a new key into the given tree.
|
||||
*/
|
||||
vieter_tree_error vieter_tree_node_insert(vieter_tree_node *root, uint64_t key, void *data);
|
||||
|
||||
/*
|
||||
|
@ -31,20 +40,41 @@ vieter_tree_error vieter_tree_node_insert(vieter_tree_node *root, uint64_t key,
|
|||
*/
|
||||
vieter_tree_error vieter_tree_node_search_node(vieter_tree_node **out, vieter_tree_node *root, uint64_t key);
|
||||
|
||||
/*
|
||||
* Search for the data represented by the given key.
|
||||
*/
|
||||
vieter_tree_error vieter_tree_node_search(void **out, vieter_tree_node *root, uint64_t key);
|
||||
|
||||
/*
|
||||
* Remove the data associated with the given key.
|
||||
*/
|
||||
vieter_tree_error vieter_tree_node_remove(void **out, vieter_tree_node **root_ptr, uint64_t key);
|
||||
|
||||
void vieter_tree_node_replace_with_child(vieter_tree_node *to_replace, vieter_tree_node *replacement);
|
||||
|
||||
/*
|
||||
* Set a node's bit flag to the given value.
|
||||
*/
|
||||
void vieter_tree_node_set(vieter_tree_node *node, vieter_tree_node_flag flag, bool value);
|
||||
|
||||
/*
|
||||
* Get whether a node's bit flag is set.
|
||||
*/
|
||||
bool vieter_tree_node_get(vieter_tree_node *node, vieter_tree_node_flag flag);
|
||||
|
||||
/*
|
||||
* Add a new child to the parent, replacing either its left or right child,
|
||||
* depending on the key values.
|
||||
*/
|
||||
void vieter_tree_node_add_child(vieter_tree_node *parent, uint64_t key,
|
||||
vieter_tree_node *child);
|
||||
|
||||
/*
|
||||
* Replace a node's children array.
|
||||
*/
|
||||
void vieter_tree_node_set_children(vieter_tree_node *parent, vieter_tree_node **children);
|
||||
|
||||
/*
|
||||
* Set a node's left or right child to the given node.
|
||||
*/
|
||||
void vieter_tree_node_set_child(vieter_tree_node *parent, vieter_tree_node *child, bool right);
|
||||
|
||||
bool vieter_tree_node_validate(vieter_tree_node *node, uint64_t passed_black_nodes, uint64_t expected_black_nodes);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -65,7 +65,7 @@ void test_rotate_left() {
|
|||
}
|
||||
|
||||
TEST_LIST = {
|
||||
{"tree tree rotate right", test_rotate_right},
|
||||
{"tree tree rotate left", test_rotate_left},
|
||||
{"tree rotate right", test_rotate_right},
|
||||
{"tree rotate left", test_rotate_left},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue