Documentation
¶
Overview ¶
Package trie provides an implementation of a ternary search trie.
Example ¶
package main
import (
"fmt"
"github.com/fufuok/utils/generic/trie"
)
func main() {
tr := trie.New[int]()
tr.Put("f§oo", 1)
tr.Put("f§o", 2)
tr.Put("bar", 3)
fmt.Println(tr.Contains("§"))
fmt.Println(tr.KeysWithPrefix(""))
fmt.Println(tr.KeysWithPrefix("f§"))
}
Output: false [bar f§o f§oo] [f§o f§oo]
Index ¶
- type Trie
- func (t *Trie[V]) Contains(key string) bool
- func (t *Trie[V]) Get(key string) (v V, ok bool)
- func (t *Trie[V]) Keys() (queue []string)
- func (t *Trie[V]) KeysWithPrefix(prefix string) (queue []string)
- func (t *Trie[V]) LongestPrefix(query string) string
- func (t *Trie[V]) Put(key string, val V)
- func (t *Trie[V]) Remove(key string)
- func (t *Trie[V]) Size() int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Trie ¶
type Trie[V any] struct { // contains filtered or unexported fields }
A Trie is a data structure that supports common prefix operations.
func (*Trie[V]) KeysWithPrefix ¶
KeysWithPrefix returns all keys with prefix 'prefix'.
func (*Trie[V]) LongestPrefix ¶
LongestPrefix returns the key that is the longest prefix of 'query'.
Click to show internal directories.
Click to hide internal directories.