A simple implementation of an AVL tree (self-balancing binary search tree). It stores values associated with keys and performs insertion, deletion, and search operations in
pip install BalancedBstAvlfrom avltree import AVLTree
tree = AVLTree()
tree = tree.set(10, "a")
tree = tree.set(5, "b")
tree = tree.set(15, "c")
print(tree.find(10))
print(tree.get(5))
print(tree.items())
tree = tree.delete(10)
print(tree.items())- Insert/Update keys:
set(x, value)(inserts if not present, updates if exists) - Delete keys:
delete(x) - Check key existence:
find(x) - Retrieve values:
get(x, default=None) - Traverse:
items()(in ascending key order)
- Runtime: None (Python standard library only)
- Development:
pytestand others (install withpip install -e .[dev])
- Python 3.9, 3.10, 3.11, 3.12, 3.13
- OS: Windows / macOS / Linux
pip install -e .[dev]
pytestMIT License