Documentation
¶
Overview ¶
Package btree implements an in-memory B-Tree.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BTree ¶
type BTree[K, V any] struct { // contains filtered or unexported fields }
BTree is a generic in-memory B-Tree that can hold arbitrary keys and values.
func New ¶
New creates a new B-tree with the given comparison function, with the default branching factor tee. cmp(a, b) should return a negative number when a<b, a positive number when a>b and zero when a==b.
func NewWithTee ¶
NewWithTee is like New, but accepts a custom branching factor tee.
func (*BTree[K, V]) All ¶
All returns an iterator over all key-value pairs in the tree, in order (sorted by key).
func (*BTree[K, V]) Delete ¶
func (bt *BTree[K, V]) Delete(key K)
Delete deletes a key and its associated value from the tree. If key is not found in the tree, Delete is a no-op.
func (*BTree[K, V]) Get ¶
Get looks for the given key in the tree. It returns the associated value and ok=true; otherwise, it returns ok=false.
func (*BTree[K, V]) Insert ¶
func (bt *BTree[K, V]) Insert(key K, value V)
Insert inserts a new key=value pair into the tree. If `key` already exists in the tree, its value is replaced with `value`.
func (*BTree[K, V]) Stats ¶
Stats returns a string with statistics about this B-Tree: total number of keys, nodes, leaf nodes etc.