Go to the first, previous, next, last section, table of contents.


The Binary Tree Data Type

The binary tree is sometimes an efficient way to store data. When a binary tree is created a compare function is given to the create function (bintree-create). This function is used throughout all data entry and deletions into and out of the tree.

To use the binary tree in Elib you must put the line

(require 'bintree)

in your elisp source file.

The following functions are provided by the binary tree in the library:

(bintree-create compare-function)
Create a new empty binary tree. The argument compare-function is a function which compares two instances of the data type which is to be entered into the tree. The call (compare-function data1 data2) should return non-nil if data1 is less than data2, and nil otherwise.
(bintree-p tree)
Return t if tree is an bintree, otherwise return nil.
(bintree-compare-function tree)
Return compare-function given to bintree-create when tree was created.
(bintree-empty tree)
Return t if tree is empty, otherwise return nil.
(bintree-enter tree data)
Enter data into tree. If there already is a data element which is considered equal to data by compare-function given to bintree-create, the new element will replace the old one in the tree.
(bintree-delete tree data)
Delete the element which is considered equal to data by compare-function given to bintree-create. If there is no matching element within the tree, nothing is done to the tree.
(bintree-member tree data)
Return the element in tree which is considered equal to data by compare-function given to bintree-create. If there is no such element in the tree, return nil.
(bintree-map map-function tree)
Apply map-function to all elements in tree. The function is applied in the order in which the tree is sorted.
(bintree-first tree)
Return the first element of tree, i.e. the one who is considered first by compare-function given to bintree-create. If the tree is empty, return nil.
(bintree-last tree)
Return the last element of tree, i.e. the one who is considered last by compare-function given to bintree-create. If the tree is empty, return nil.
(bintree-copy tree)
Return a copy of tree.
(bintree-flatten tree)
Return a sorted list containing all elements of tree.
(bintree-size tree)
Return the number of elements in tree.
(bintree-clear tree)
Clear tree, i.e. make it totally empty.


Go to the first, previous, next, last section, table of contents.