Documentation ¶
Overview ¶
Package trie implements a byte trie with edge compression.
Index ¶
- type KV
- type Trie
- func (t *Trie) FindAllPfx(key string) []KV
- func (t *Trie) FindPfx(key string) (pfx string, val interface{})
- func (t *Trie) ForEach(f func(string, interface{}) bool)
- func (t *Trie) ForEachB(f func([]byte, interface{}) bool)
- func (t *Trie) ForEachPfx(pfx string, f func(string, interface{}) bool)
- func (t *Trie) Get(key string) interface{}
- func (t *Trie) Put(key string, value interface{})
- func (t *Trie) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KV ¶
type KV struct { K string V interface{} }
A KV is a key, value pair, as returned by FindAllPfx
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
A Trie maintains a sorted collection of values keyed on a string. Insertion is O(len(key)). Unlike Go's built-in map there is no distinction between a nil and a non-existent value. The zero value for Trie is an empty trie ready to use.
func (*Trie) FindAllPfx ¶
FindAllPfx returns all prefixes of key in the trie and their values.
func (*Trie) FindPfx ¶
FindPfx finds the longest prefix of key in the trie that has a non-nil value.
func (*Trie) ForEach ¶
ForEach will apply the function f to each key, value pair in the Trie in sorted (depth-first pre-)order. if f returns false, the iteration will stop.
func (*Trie) ForEachB ¶
ForEachB will apply the function f to each key, value pair in the Trie in sorted (depth-first pre-)order. if f returns false, the iteration will stop.
func (*Trie) ForEachPfx ¶
ForEachPfx applies ForEach to the sub-trie that starts with the given prefix.