package
module
Version:
v1.0.0
Opens a new window with list of versions in this module.
Published: Mar 16, 2025
License: Apache-2.0
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 1
Opens a new window with list of known importers.
README
¶
Radix
This package provides a generic implementation of a radix tree.
Installing
go get gitlab.com/romalor/radix@v1
Documentation
¶
package radix represents an implementation of a PATRICA tree.
-
func All[K cmp.Ordered, V any](t *Tree[K, V]) iter.Seq2[[]K, V]
-
func Keys[K cmp.Ordered, V any](t *Tree[K, V]) iter.Seq[[]K]
-
func Values[K cmp.Ordered, V any](t *Tree[K, V]) iter.Seq[V]
-
func Zero[T any]() T
-
type Tree
-
func (t *Tree[K, V]) Delete(key []K)
-
func (t *Tree[K, V]) Get(key []K) (V, bool)
-
func (t *Tree[K, V]) Insert(key []K, value V)
-
func (t *Tree[K, V]) Len() int
-
func (t *Tree[K, V]) Max() []K
-
func (t *Tree[K, V]) Print()
-
func (t *Tree[K, V]) Search(key []K) (V, bool)
All returns an iterator over the key-value pairs in t.
Iteration order is always guaranteed to be in the ascending order
of the keys in t.
Keys returns an iterator over the keys stored in t.
Iteration order is always guaranteed to be in ascending order.
Values returns an iterator over the values stored in t.
Iteration order is always guaranteed to based on the ascending
order of the keys in t.
Zero returns the zero value for T.
Tree represents a radix tree.
Collect collects key-value pairs from seq to populate a new tree and
returns it.
New creates a new radix tree.
func (t *Tree[K, V]) Delete(key []K)
Delete removes a node from the tree. Not concurrency safe.
func (t *Tree[K, V]) Get(key []K) (V, bool)
Get retrieves a value by its key.
func (t *Tree[K, V]) Insert(key []K, value V)
Insert adds a key-value pair to the tree. Not concurrency safe.
Len returns the number of keys stored in the tree.
func (t *Tree[K, V]) Max() []K
Max returns the longest key stored in the tree.
The precedence of Max is in descending order. If
two keys are of equal length, max will return the
last one found.
Example:
"apple"
"bands" <- Returned from max.
If the tree is empty, Max returns an empty slice.
func (t *Tree[K, V]) Print()
Print recursively prints the contents of the tree.
func (t *Tree[K, V]) Search(key []K) (V, bool)
Search returns the longest prefix match for a key.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.