|
MentOS
0.8.0
The Mentoring Operating System
|
Red/Black tree. More...
Classes | |
| struct | rbtree_node_t |
| Stores information of a node. More... | |
| struct | rbtree_t |
| Stores information of a rbtree. More... | |
| struct | rbtree_iter_t |
| Stores information for iterating a rbtree. More... | |
Functions | |
| rbtree_node_t * | rbtree_node_alloc (void) |
| Allocate memory for a node. More... | |
| rbtree_node_t * | rbtree_node_init (rbtree_node_t *node, void *value) |
| Initializes the already allocated node. More... | |
| rbtree_node_t * | rbtree_node_create (void *value) |
| Allocate memory for a node and sets its value. 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... | |
| static int | rbtree_node_is_red (const rbtree_node_t *node) |
| Checks if the node is red. More... | |
| static rbtree_node_t * | rbtree_node_rotate (rbtree_node_t *node, int dir) |
| Performs a node rotation. More... | |
| static rbtree_node_t * | rbtree_node_rotate2 (rbtree_node_t *node, int dir) |
| Performs a double rotation. More... | |
| static int | rbtree_tree_node_cmp_ptr_cb (rbtree_t *tree, rbtree_node_t *a, rbtree_node_t *b) |
| Peforms a comparison between the pointers of two elements. More... | |
| static void | rbtree_tree_node_dealloc_cb (rbtree_t *tree, rbtree_node_t *node) |
| Default deallocation callback. More... | |
| rbtree_t * | rbtree_tree_alloc (void) |
| Allocate memory for a tree. More... | |
| rbtree_t * | rbtree_tree_init (rbtree_t *tree, rbtree_tree_node_cmp_f node_cmp_cb) |
| Initializes the tree. More... | |
| rbtree_t * | rbtree_tree_create (rbtree_tree_node_cmp_f node_cb) |
| Allocate memory for a tree and sets the function used to compare nodes. 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_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... | |
| 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... | |
| 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... | |
| static void * | rbtree_iter_start (rbtree_iter_t *iter, rbtree_t *tree, int dir) |
| Internal function, init traversal object, dir determines whether to begin traversal at the smallest or largest valued node. More... | |
| static void * | rbtree_iter_move (rbtree_iter_t *iter, int dir) |
| Traverse a red black tree in the user-specified direction (0 asc, 1 desc) 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... | |
| static void | rbtree_tree_print_iter (rbtree_t *tree, rbtree_node_t *node, rbtree_tree_node_f fun) |
| Prints the tree using a user-defined function. 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. |
|
static |
Traverse a red black tree in the user-specified direction (0 asc, 1 desc)
| iter | the iterator. |
| dir | the direction. |
| 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. |
|
static |
Internal function, init traversal object, dir determines whether to begin traversal at the smallest or largest valued node.
| iter | the iterator. |
| tree | the tree. |
| dir | the direction. |
| 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. |
|
static |
Checks if the node is red.
| node | the node to check. |
|
static |
Performs a node rotation.
| node | the node. |
| dir | the direction of the rotation (0: left, 1: right). |
|
static |
Performs a double rotation.
| node | the node. |
| dir | the direction of the rotation (0: left, 1: right). |
Suppose U has a parent V and a grandparent W. Then two successive rotations on U will ensure that V and W are descendents of U.
| 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. |
|
static |
Peforms a comparison between the pointers of two elements.
| tree | the tree. |
| a | the first element. |
| b | the second element. |
|
static |
Default deallocation callback.
| tree | the tree. |
| node | the node. |
| 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. |
|
static |
Prints the tree using a user-defined function.
| tree | the tree. |
| node | the current node. |
| fun | the print function. |
| 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. |