Documentation
¶
Overview ¶
This package exposes a simple Trie implementation
Index ¶
- type PrefixInfo
- type PrefixIteratorCallback
- type Stack
- type Trie
- func (t *Trie) AppendWord(phrase string)
- func (t *Trie) AppendWords(words ...string)
- func (t *Trie) ClosestWords(word string) []interface{}
- func (t *Trie) EachPrefix(callback PrefixIteratorCallback)
- func (t *Trie) HasWord(word string) bool
- func (t *Trie) IsRoot() bool
- func (t *Trie) Words() (words []interface{})
- type TrieNode
- type TriePtr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PrefixInfo ¶
type PrefixIteratorCallback ¶
type PrefixIteratorCallback func(PrefixInfo) (skip_subtree, halt bool)
This call back is used by EachPrefix function and called for every prefix in the radix tree. Returning true for the skip_subtree value makes the algorithm skip the entire subtree that is about to explore. This feature can enable very fast tree iterations despite the DFS nature of the traversal.
type Trie ¶
type Trie struct {
IsWord bool
Parent *Trie
Children []*Trie
// contains filtered or unexported fields
}
func (*Trie) AppendWord ¶
Appends a word to the trie The algorithm follows the BFS traversal principles implemented iteratively. Given suffix is treated as a full word.
func (*Trie) AppendWords ¶
func (*Trie) ClosestWords ¶
Returns an array of objects that are associated with the words closest to the specified word param
func (*Trie) EachPrefix ¶
func (t *Trie) EachPrefix(callback PrefixIteratorCallback)
Iterates for each prefix in the radix tree calling the given callback. The given callback can be used to guide the tree traversal. The traversal is based on a DFS implementation backed by a stack to handle the nodes to iterate to. A special implementation of the stack allows for a O(1) push for all the node children at once keeping the whole traversal MAX(O(N)) where N is the number of nodes.