fltrie

package
v0.0.0-...-5ae7e60 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyBuilt  = errors.New("flash trie is already built")
	ErrInvalidHeight = errors.New("flash trie height does not match config KeyBits")
	ErrInvalidRoute  = errors.New("encoded route length does not match config KeyBits")
)

Functions

This section is empty.

Types

type Adapter

type Adapter[K any] interface {
	Encode(key K) (string, error)
	KeyBits() uint
}

Adapter encodes a query key into a full-length binary string for lookup.

type Config

type Config struct {
	KeyBits   uint // total key length in bits (32 for IPv4, 128 for IPv6, etc.)
	Stride    uint // bits per subdivision level (default: 8)
	CompSize  int  // pctrie compression factor (default: 2)
	TrieDepth uint // number of stride-levels covered by direct trie (default: 2)
}

Config holds the parameters for a FlashTrie.

type FLTrie

type FLTrie[K, V any] struct {
	// contains filtered or unexported fields
}

FLTrie represents flash trie structure.

func New

func New[K, V any](adapter Adapter[K], cfg Config) *FLTrie[K, V]

New creates empty and unbuilt flash trie.

func (*FLTrie[K, V]) Add

func (fl *FLTrie[K, V]) Add(route string, value V) error

Add adds new route into unbuilt flash trie. Given route must be in binary regex format e.g. *, 11*.

func (*FLTrie[K, V]) All

func (fl *FLTrie[K, V]) All() iter.Seq2[string, V]

All returns an iterator over all (prefix, value) pairs stored in the trie.

func (*FLTrie[K, V]) Build

func (fl *FLTrie[K, V]) Build() error

Build builds flash trie multi-level hierarchy.

func (*FLTrie[K, V]) Lookup

func (fl *FLTrie[K, V]) Lookup(key K) (V, bool, error)

Lookup looks up given key and returns found value.

Jump to

Keyboard shortcuts

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