Documentation
¶
Index ¶
- type InspectFunc
- type Item
- type Tree
- func (t *Tree[T]) Delete(key []byte) bool
- func (t *Tree[T]) DeletePrefix(prefix []byte) bool
- func (t *Tree[T]) Get(key []byte) (T, bool)
- func (t *Tree[T]) Inspect(inspectFn InspectFunc[T])
- func (t *Tree[T]) Iter() iter.Seq2[[]byte, T]
- func (t *Tree[T]) IterAt(key []byte) iter.Seq2[[]byte, T]
- func (t *Tree[T]) IterPath(key []byte) iter.Seq2[[]byte, T]
- func (t *Tree[T]) Len() int
- func (t *Tree[T]) Put(key []byte, value T) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InspectFunc ¶
type InspectFunc[T any] func(link, prefix, key []byte, depth, children int, hasValue bool, value T) bool
InspectFunc is the type of the function called for each node visited by Inspect. The key argument contains the key at which the node is located, the depth is the distance from the root of the tree, and children is the number of children the node has.
If the function returns true Inspect stops immediately and returns.
type Tree ¶
type Tree[T any] struct { // contains filtered or unexported fields }
Tree is a radix tree of bytes keys and any values.
func (*Tree[T]) Delete ¶
Delete removes the value associated with the given key. Returns true if there was a value stored for the key. If the node or any of its ancestors becomes childless as a result, they are removed from the tree.
func (*Tree[T]) DeletePrefix ¶
DeletePrefix removes all values whose key is prefixed by the given prefix. Returns true if any values were removed.
func (*Tree[T]) Get ¶
Get returns the value stored at the given key. Returns false if there is no value present for the key.
func (*Tree[T]) Inspect ¶
func (t *Tree[T]) Inspect(inspectFn InspectFunc[T])
Inspect walks every node of the tree, whether or not it holds a value, calling inspectFn with information about each node. This allows the structure of the tree to be examined and detailed statistics to be collected.
If inspectFn returns false, the traversal is stopped and Inspect returns.
The tree is traversed in lexical order, making the output deterministic.
func (*Tree[T]) Iter ¶
Iter visits all nodes in the tree, yielding the key and value of each.
The tree is traversed in lexical order, making the output deterministic.
func (*Tree[T]) IterAt ¶
IterAt visits all nodes whose keys match or are prefixed by the specified key, yielding the key and value of each. An empty key "" to visits all nodes, and is the same as calling Iter.
The tree is traversed in lexical order, making the output deterministic.
func (*Tree[T]) IterPath ¶
IterPath returns an iterator that visits each node along the path from the root to the node at the given key. yielding the key and value of each.
The tree is traversed in lexical order, making the output deterministic.