import "github.com/zyedidia/generic/btree"
Package btree provides an implementation of a B-tree. A B-tree is a logarithmic search tree that maintains key-value pairs in sorted order. It is not binary because it stores more than 2 data entries per node. The branching factor for this tree is 64.
Example
package main
import (
"fmt"
g "github.com/zyedidia/generic"
"github.com/zyedidia/generic/btree"
)
func main() {
tree := btree.New[g.Int, g.String]()
tree.Put(42, "foo")
tree.Put(-10, "bar")
tree.Put(0, "baz")
tree.Iter().For(func(kv btree.KV[g.Int, g.String]) {
fmt.Println(kv.Key, kv.Val)
})
}
-10 bar
0 baz
42 foo
type KV[K g.Lesser[K], V any] struct {
Key K
Val V
}
Tree implements a B-tree.
type Tree[K g.Lesser[K], V any] struct {
// contains filtered or unexported fields
}
func New[K g.Lesser[K], V any]() *Tree[K, V]
New returns an empty B-tree.
func (t *Tree[K, V]) Get(key K) (V, bool)
Get returns the value associated with 'key'.
func (t *Tree[K, V]) GetZ(key K) V
GetZ is the same as Get but returns the zero value when nothing is found.
func (t *Tree[K, V]) Iter() iter.Iter[KV[K, V]]
Iter returns an iterator over all key-value pairs that iterates in sorted order from smallest to largest.
func (t *Tree[K, V]) Put(key K, val V)
Put associates 'key' with 'val'.
func (t *Tree[K, V]) Size() int
Size returns the number of elements in the tree.
Generated by gomarkdoc