The AVL tree data types provides a balanced binary tree. The tree will remain balanced throughout its entire life time, regardless of in which order elements are entered into or deleted from the tree.
Although an AVL tree is not perfectly balanced, it has almost the same performance as if it was. The definition of an AVL tree is that the difference in depth of the two branches of a particular node is at most 1. This criterium is enough to make the performance of searching in an AVL tree very close to a perfectly balanced tree, but will simplify the entering and deleting of data significantly.
All data that is entered into an AVL tree should be of the same type. If they are not, there are no way to compare two elements and this is essential for entering and deleting data from the tree. When a tree is created, a compare function is given to the create function. This function is used throughout the life of the tree in all subsequent insertions and deletions.
To use the Elib AVL tree, you must put the line
(require 'avltree)
in your elisp source file.
The following functions are provided by the AVL tree in the library:
(avltree-create compare-function)
(compare-function data1 data2)
should return non-nil
if data1
is less than data2
,
and nil
otherwise.
(avltree-p tree)
t
if tree is an avltree, otherwise return nil
.
(avltree-compare-function tree)
compare-function
given to avltree-create
when
tree was created.
(avltree-empty tree)
t
if tree is empty, otherwise return nil
.
(avltree-enter tree data)
compare-function
given to
avltree-create
, the new element will replace the old one in the
tree.
(avltree-delete tree data)
compare-function
given to avltree-create
. If there
is no matching element within the tree, nothing is done to the tree.
(avltree-member tree data)
compare-function
given to avltree-create
. If there
is no such element in the tree, return nil
.
(avltree-map map-function tree)
(avltree-first tree)
compare-function
given to avltree-create
. If the
tree is empty, return nil
.
(avltree-last tree)
compare-function
given to avltree-create
. If the
tree is empty, return nil
.
(avltree-copy tree)
(avltree-flatten tree)
(avltree-size tree)
(avltree-clear tree)
Go to the first, previous, next, last section, table of contents.