An efficient implementation of Prof. Arne Andersson's General Balanced Trees. These have no storage overhead compared to unbalanced binary trees, and their performance is in general better than AVL trees.
Data structure:
- {Size, Tree}, where `Tree' is composed of nodes of the form:
- {Key, Value, Smaller, Bigger}, and the "empty tree" node:
- nil.
There is no attempt to balance trees after deletions. Since deletions do not increase the height of a tree, this should be OK.
Original balance condition h(T) <= ceil(c * log(|T|)) has been changed to the similar (but not quite equivalent) condition 2 ^ h(T) <= |T| ^ c. This should also be OK.
Performance is comparable to the AVL trees in the Erlang book (and faster in general due to less overhead); the difference is that deletion works for these trees, but not for the book's trees. Behaviour is logarithmic (as it should be).
gb_tree() = a GB tree
Rebalances
Removes the node with key
Removes the node with key
Returns a new empty tree
Inserts
Turns an ordered list
Retrieves the value stored with
Looks up
Inserts
Returns
Returns
Returns an iterator that can be used for traversing the
entries of
Returns the keys in
Returns
maps the function F(K, V1) -> V2 to all key-value pairs of the tree Tree1 and returns a new tree Tree2 with the same set of keys as Tree1 and the new set of values V2.
Returns
Returns the number of nodes in
Returns
Returns
Returns
Converts a tree into an ordered list of key-value tuples.
Updates
Returns the values in