Documentation ¶
Index ¶
- type InspectFunc
- 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) (value T, ok bool)
- func (t *Tree[T]) Inspect(inspectFn InspectFunc[T])
- func (t *Tree[T]) Len() int
- func (t *Tree[T]) Put(key []byte, value T) bool
- func (t *Tree[T]) Walk(key []byte, walkFn WalkFunc)
- func (t *Tree[T]) WalkPath(key []byte, walkFn WalkFunc)
- type WalkFunc
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]) Put ¶
Put inserts the value into the tree at the given key, replacing any existing items. It returns true if it adds a new value, false if it replaces an existing value.
func (*Tree[T]) Walk ¶
Walk visits all nodes whose keys match or are prefixed by the specified key, calling walkFn for each value found. If walkFn returns true, Walk returns. Use empty key "" to visit all nodes starting from the root or the Tree.
The tree is traversed in lexical order, making the output deterministic.