|
void | avl_create (avl_tree_t *tree, int(*compar)(const void *, const void *), size_t size, size_t offset) |
|
void * | avl_find (const avl_tree_t *tree, const void *node, avl_index_t *where) |
|
void | avl_insert (avl_tree_t *tree, void *node, avl_index_t where) |
|
void | avl_insert_here (avl_tree_t *tree, void *new_data, void *here, int direction) |
|
void * | avl_first (const avl_tree_t *tree) |
|
void * | avl_last (const avl_tree_t *tree) |
|
void * | avl_nearest (const avl_tree_t *tree, avl_index_t where, int direction) |
|
void | avl_add (avl_tree_t *tree, void *node) |
|
void | avl_remove (avl_tree_t *tree, void *node) |
|
bool_t | avl_update (avl_tree_t *, void *) |
|
bool_t | avl_update_lt (avl_tree_t *, void *) |
|
bool_t | avl_update_gt (avl_tree_t *, void *) |
|
unsigned long | avl_numnodes (const avl_tree_t *tree) |
|
bool_t | avl_is_empty (avl_tree_t *tree) |
|
void * | avl_destroy_nodes (avl_tree_t *tree, void **cookie) |
|
void | avl_destroy (avl_tree_t *tree) |
|
This is a generic implemenatation of AVL trees for use in the Solaris kernel. The interfaces provide an efficient way of implementing an ordered set of data structures.
AVL trees provide an alternative to using an ordered linked list. Using AVL trees will usually be faster, however they requires more storage. An ordered linked list in general requires 2 pointers in each data structure. The AVL tree implementation uses 3 pointers. The following chart gives the approximate performance of operations with the different approaches:
Operation Link List AVL tree
lookup O(n) O(log(n))
insert 1 node constant constant
delete 1 node constant between constant and O(log(n))
delete all nodes O(n) O(n)
visit the next or prev node constant between constant and O(log(n))
The data structure nodes are anchored at an avl_tree_t (the equivalent of a list header) and the individual nodes will have a field of type "avl_node_t" (corresponding to list pointers).
The type avl_index_t is used to indicate a position in the list for certain calls.
The usage scenario is generally:
- Create the list/tree with: avl_create()
followed by any mixture of:
2a. Insert nodes with: avl_add(), or avl_find() and avl_insert()
2b. Visited elements with: avl_first() - returns the lowest valued node avl_last() - returns the highest valued node AVL_NEXT() - given a node go to next higher one AVL_PREV() - given a node go to previous lower one
2c. Find the node with the closest value either less than or greater than a given value with avl_nearest().
2d. Remove individual nodes from the list/tree with avl_remove().
and finally when the list is being destroyed
- Use avl_destroy_nodes() to quickly process/free up any remaining nodes. Note that once you use avl_destroy_nodes(), you can no longer use any routine except avl_destroy_nodes() and avl_destoy().
- Use avl_destroy() to destroy the AVL tree itself.
Any locking for multiple thread access is up to the user to provide, just as is needed for any linked list implementation.
Definition in file avl.h.