A pure python functional-style self-balancing binary search tree
implementation, with an object-oriented wrapper. Useful for maintaining
sorted sets, traversing sets in order, and closest-match lookups.
|
node(l,
v,
r,
b)
Make an AVL tree node, consisting of a left tree, a value, a right
tree, and the "balance factor": the difference in lengths
between the right and left sides, respectively. |
source code
|
|
|
|
|
debug(tree,
level=0)
Print out a debugging representation of an AVL tree. |
source code
|
|
|
fromseq(seq)
Populate and return an AVL tree from an iterable sequence. |
source code
|
|
|
_balance(hdiff,
l,
v,
r,
b)
Internal method to rebalance an AVL tree, called as needed. |
source code
|
|
|
|
|
|
|
|
|
iterate(tree)
Iterate over an AVL tree, starting with the lowest-ordered value. |
source code
|
|
|
iteratereversed(tree)
Iterate over an AVL tree, starting with the highest-ordered value. |
source code
|
|