-
Class Summary
| Class |
Description |
| avl_index_t |
An opaque type used to locate a position in the tree where a node
would be inserted.
|
| avl_node_t |
The data nodes in the AVL tree must have a field of this type.
|
| avl_tree_t |
Type used for the root of the AVL tree.
|
Package org.jvnet.solaris.avl Description
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:
1. 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
3. 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().
4. 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.