Individual trees¶
-
class
larch.tree.
BTree
(forest, node_store, root_id)¶ A balanced search tree (copy-on-write B-tree).
The tree belongs to a forest. The tree nodes are stored in an external node store; see the
NodeStore
class.root_id
gives the id of the root node of the tree. The root node must be unique to this tree, as it is modified in place.root_id
may also beNone
, in which case a new node is created automatically to serve as the root node.-
count_range
(minkey, maxkey)¶ Return number of keys in range.
-
insert
(key, value)¶ Insert a new key/value pair into the tree.
If the key already existed in the tree, the old value is silently forgotten.
-
lookup
(key)¶ Return value corresponding to
key
.If the key is not in the tree, raise
KeyError
.
-
lookup_range
(minkey, maxkey)¶ Return list of (key, value) pairs for all keys in a range.
minkey
andmaxkey
are included in range.
-
range_is_empty
(minkey, maxkey)¶ Is a range empty in the tree?
This is faster than doing a range lookup for the same range, and checking if there are any keys returned.
-
remove
(key)¶ Remove
key
and its associated value from tree.If key is not in the tree,
KeyValue
is raised.
-
remove_range
(minkey, maxkey)¶ Remove all keys in the given range.
Range is inclusive.
-
-
exception
larch.tree.
KeySizeMismatch
(key, wanted_size)¶ User tried to use key of wrong size.
-
exception
larch.tree.
ValueTooLarge
(value, max_size)¶ User tried ot use a vlaue htat is too large for a node.