radixtree

package
v0.0.0-...-2344004 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

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 Item

type Item[T any] struct {
	// contains filtered or unexported fields
}

func (*Item[T]) Key

func (kv *Item[T]) Key() []byte

func (*Item[T]) Value

func (kv *Item[T]) Value() T

type Tree

type Tree[T any] struct {
	// contains filtered or unexported fields
}

Tree is a radix tree of bytes keys and any values.

func New

func New[T any]() *Tree[T]

New creates a new bytes-based radix tree

func (*Tree[T]) Delete

func (t *Tree[T]) Delete(key []byte) bool

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

func (t *Tree[T]) DeletePrefix(prefix []byte) bool

DeletePrefix removes all values whose key is prefixed by the given prefix. Returns true if any values were removed.

func (*Tree[T]) Get

func (t *Tree[T]) Get(key []byte) (T, bool)

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

func (t *Tree[T]) Iter() iter.Seq2[[]byte, T]

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

func (t *Tree[T]) IterAt(key []byte) iter.Seq2[[]byte, T]

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

func (t *Tree[T]) IterPath(key []byte) iter.Seq2[[]byte, T]

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.

func (*Tree[T]) Len

func (t *Tree[T]) Len() int

Len returns the number of values stored in the tree.

func (*Tree[T]) Put

func (t *Tree[T]) Put(key []byte, value T) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL