MentOS
0.8.0
The Mentoring Operating System
|
Red/Black tree. More...
Go to the source code of this file.
Macros | |
#define | RBTREE_ITER_MAX_HEIGHT 64 |
Tallest allowable tree to iterate. | |
Typedefs | |
typedef struct rbtree_node_t | rbtree_node_t |
Node of the tree. | |
typedef struct rbtree_t | rbtree_t |
The tree itself. | |
typedef struct rbtree_iter_t | rbtree_iter_t |
Iterator for traversing the tree. | |
typedef int(* | rbtree_tree_cmp_f) (rbtree_t *tree, rbtree_node_t *a, void *arg) |
Function for comparing elements in the tree. | |
typedef int(* | rbtree_tree_node_cmp_f) (rbtree_t *tree, rbtree_node_t *a, rbtree_node_t *b) |
Function for comparing elements in the tree. | |
typedef void(* | rbtree_tree_node_f) (rbtree_t *tree, rbtree_node_t *node) |
Callback to call on elements of the tree. | |
Functions | |
rbtree_node_t * | rbtree_node_alloc (void) |
Allocate memory for a node. More... | |
rbtree_node_t * | rbtree_node_create (void *value) |
Allocate memory for a node and sets its value. More... | |
rbtree_node_t * | rbtree_node_init (rbtree_node_t *node, void *value) |
Initializes the already allocated node. More... | |
void * | rbtree_node_get_value (rbtree_node_t *node) |
Provides access to the value associated to a node. More... | |
void | rbtree_node_dealloc (rbtree_node_t *node) |
Deallocate a node. More... | |
rbtree_t * | rbtree_tree_alloc (void) |
Allocate memory for a tree. More... | |
rbtree_t * | rbtree_tree_create (rbtree_tree_node_cmp_f cmp) |
Allocate memory for a tree and sets the function used to compare nodes. More... | |
rbtree_t * | rbtree_tree_init (rbtree_t *tree, rbtree_tree_node_cmp_f cmp) |
Initializes the tree. More... | |
void | rbtree_tree_dealloc (rbtree_t *tree, rbtree_tree_node_f node_cb) |
Deallocate a node. More... | |
void * | rbtree_tree_find (rbtree_t *tree, void *value) |
Searches the node inside the tree with the given value. More... | |
void * | rbtree_tree_find_by_value (rbtree_t *tree, rbtree_tree_cmp_f cmp_fun, void *value) |
Searches the node inside the tree with the given value. More... | |
int | rbtree_tree_insert (rbtree_t *tree, void *value) |
Interts the value inside the tree. More... | |
int | rbtree_tree_remove (rbtree_t *tree, void *value) |
Removes the value from the given tree. More... | |
unsigned int | rbtree_tree_size (rbtree_t *tree) |
Returns the size of the tree. More... | |
int | rbtree_tree_insert_node (rbtree_t *tree, rbtree_node_t *node) |
Interts the value inside the tree. More... | |
int | rbtree_tree_remove_with_cb (rbtree_t *tree, void *value, rbtree_tree_node_f node_cb) |
Removes the value from the tree. More... | |
rbtree_iter_t * | rbtree_iter_alloc (void) |
Allocate the memory for the iterator. More... | |
rbtree_iter_t * | rbtree_iter_init (rbtree_iter_t *iter) |
Deallocate the memory for the iterator. More... | |
rbtree_iter_t * | rbtree_iter_create (void) |
Allocate the memory for the iterator and initializes it. More... | |
void | rbtree_iter_dealloc (rbtree_iter_t *iter) |
Deallocate the memory for the iterator. More... | |
void * | rbtree_iter_first (rbtree_iter_t *iter, rbtree_t *tree) |
Initializes the iterator the the first element of the tree. More... | |
void * | rbtree_iter_last (rbtree_iter_t *iter, rbtree_t *tree) |
Initializes the iterator the the last element of the tree. More... | |
void * | rbtree_iter_next (rbtree_iter_t *iter) |
Moves the iterator to the next element. More... | |
void * | rbtree_iter_prev (rbtree_iter_t *iter) |
Moves the iterator to the previous element. More... | |
int | rbtree_tree_test (rbtree_t *tree, rbtree_node_t *root) |
Checks the tree. More... | |
void | rbtree_tree_print (rbtree_t *tree, rbtree_tree_node_f fun) |
Prints the tree using the provided callback. More... | |
Red/Black tree.
rbtree_iter_t* rbtree_iter_alloc | ( | void | ) |
Allocate the memory for the iterator.
rbtree_iter_t* rbtree_iter_create | ( | void | ) |
Allocate the memory for the iterator and initializes it.
void rbtree_iter_dealloc | ( | rbtree_iter_t * | iter | ) |
Deallocate the memory for the iterator.
iter | Pointer to the allocated iterator. |
void* rbtree_iter_first | ( | rbtree_iter_t * | iter, |
rbtree_t * | tree | ||
) |
Initializes the iterator the the first element of the tree.
iter | The iterator we want to initialize. |
tree | The tree. |
rbtree_iter_t* rbtree_iter_init | ( | rbtree_iter_t * | iter | ) |
Deallocate the memory for the iterator.
iter | Pointer to the allocated iterator. |
void* rbtree_iter_last | ( | rbtree_iter_t * | iter, |
rbtree_t * | tree | ||
) |
Initializes the iterator the the last element of the tree.
iter | The iterator we want to initialize. |
tree | The tree. |
void* rbtree_iter_next | ( | rbtree_iter_t * | iter | ) |
Moves the iterator to the next element.
iter | The iterator. |
void* rbtree_iter_prev | ( | rbtree_iter_t * | iter | ) |
Moves the iterator to the previous element.
iter | The iterator. |
rbtree_node_t* rbtree_node_alloc | ( | void | ) |
Allocate memory for a node.
rbtree_node_t* rbtree_node_create | ( | void * | value | ) |
Allocate memory for a node and sets its value.
value | Value to associated node. |
void rbtree_node_dealloc | ( | rbtree_node_t * | node | ) |
Deallocate a node.
node | The node to destroy. |
void* rbtree_node_get_value | ( | rbtree_node_t * | node | ) |
Provides access to the value associated to a node.
node | The node itself. |
rbtree_node_t* rbtree_node_init | ( | rbtree_node_t * | node, |
void * | value | ||
) |
Initializes the already allocated node.
node | The node itself. |
value | The value associated to the node. |
rbtree_t* rbtree_tree_alloc | ( | void | ) |
Allocate memory for a tree.
rbtree_t* rbtree_tree_create | ( | rbtree_tree_node_cmp_f | cmp | ) |
Allocate memory for a tree and sets the function used to compare nodes.
cmp | Function used to compare elements of the tree. |
void rbtree_tree_dealloc | ( | rbtree_t * | tree, |
rbtree_tree_node_f | node_cb | ||
) |
Deallocate a node.
tree | The tree to destroy. |
node_cb | The function called on each element of the tree before destroying the tree. |
void* rbtree_tree_find | ( | rbtree_t * | tree, |
void * | value | ||
) |
Searches the node inside the tree with the given value.
tree | The tree. |
value | The value to search. |
void* rbtree_tree_find_by_value | ( | rbtree_t * | tree, |
rbtree_tree_cmp_f | cmp_fun, | ||
void * | value | ||
) |
Searches the node inside the tree with the given value.
tree | The tree. |
cmp_fun | The node compare function. |
value | The value to search. |
rbtree_t* rbtree_tree_init | ( | rbtree_t * | tree, |
rbtree_tree_node_cmp_f | cmp | ||
) |
Initializes the tree.
tree | The tree to initialize. |
cmp | The compare function to associate to the tree. |
int rbtree_tree_insert | ( | rbtree_t * | tree, |
void * | value | ||
) |
Interts the value inside the tree.
tree | The tree. |
value | The value to insert. |
int rbtree_tree_insert_node | ( | rbtree_t * | tree, |
rbtree_node_t * | node | ||
) |
Interts the value inside the tree.
tree | The tree. |
node | The node to insert. |
void rbtree_tree_print | ( | rbtree_t * | tree, |
rbtree_tree_node_f | fun | ||
) |
Prints the tree using the provided callback.
tree | The tree. |
fun | The print callback. |
int rbtree_tree_remove | ( | rbtree_t * | tree, |
void * | value | ||
) |
Removes the value from the given tree.
tree | The tree. |
value | The value to search. |
int rbtree_tree_remove_with_cb | ( | rbtree_t * | tree, |
void * | value, | ||
rbtree_tree_node_f | node_cb | ||
) |
Removes the value from the tree.
tree | The tree. |
value | The value to remove. |
node_cb | The callback to call on the node before removing the node. |
unsigned int rbtree_tree_size | ( | rbtree_t * | tree | ) |
Returns the size of the tree.
tree | The tree. |
int rbtree_tree_test | ( | rbtree_t * | tree, |
rbtree_node_t * | root | ||
) |
Checks the tree.
tree | The tree. |
root | The root of the tree. |