func NewBPTree32
NewBPTree32 creates a new empty B+ tree with fanout 32.
Package bptree provides a mutable B+ tree implementation for storing key-value data in Gno realms. It implements the ...
Package bptree provides a mutable B+ tree implementation for storing key-value data in Gno realms. It implements the same ITree interface as the avl package but uses a B+ tree internally for better cache locality and fewer pointer dereferences per operation.
The fanout (maximum number of children per inner node, and maximum number of entries per leaf node) is configurable:
The zero value is usable as an empty tree with fanout 32:
NewBPTree32 creates a new empty B+ tree with fanout 32.
NewBPTreeN creates a new empty B+ tree with the given fanout. It panics when fanout is lower than 4.
The zero value is usable as an empty tree with fanout 32.
Get retrieves the value associated with the given key. It returns the value if the key exists, or nil if it doesn't. This allows for a simpler usage pattern with type assertions:
Use Has to distinguish a stored nil value from a missing key.
GetByIndex returns the key-value pair at the given 0-based index. Panics if index is out of range.
Iterate calls cb for each key-value pair in [start, end) ascending order. Empty start/end means no bound. Returns true if stopped early by cb. The tree must not be modified during iteration (no Set or Remove from the callback).
IterateByOffset calls cb for count entries starting at the offset-th entry in ascending order. Returns true if stopped early by cb. The tree must not be modified during iteration (no Set or Remove from the callback).
Remove deletes a key. Returns the old value and true if the key was found.
ReverseIterate calls cb for each key-value pair in [start, end] descending order. Empty start/end means no bound. Returns true if stopped early by cb. The tree must not be modified during iteration (no Set or Remove from the callback).
ReverseIterateByOffset calls cb for count entries starting at the offset-th entry from the end, in descending order. Returns true if stopped early by cb. The tree must not be modified during iteration (no Set or Remove from the callback).
Set inserts or updates a key-value pair. Returns true if the key already existed.
1type ITree interface {
2 Size() int
3 Has(key string) bool
4 Get(key string) any
5 GetByIndex(index int) (key string, value any)
6 Iterate(start, end string, cb IterCbFn) bool
7 ReverseIterate(start, end string, cb IterCbFn) bool
8 IterateByOffset(offset int, count int, cb IterCbFn) bool
9 ReverseIterateByOffset(offset int, count int, cb IterCbFn) bool
10 Set(key string, value any) (updated bool)
11 Remove(key string) (value any, removed bool)
12}