Documentation ¶
Overview ¶
Package trie provides Trie data structures in golang.
Wikipedia: https://en.wikipedia.org/wiki/Trie
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents each node in Trie.
Example ¶
// creates a new node node := NewNode() // adds words node.Insert("nikola") node.Insert("tesla") // check size and capacity fmt.Println(node.Size()) // 2 words fmt.Println(node.Capacity()) // 12 nodes // finds words fmt.Println(node.Find("thomas")) // false fmt.Println(node.Find("edison")) // false fmt.Println(node.Find("nikola")) // true // remove a word, and check it is gone node.Remove("tesla") fmt.Println(node.Find("tesla")) // false // size and capacity have changed fmt.Println(node.Size()) // 1 word left fmt.Println(node.Capacity()) // 12 nodes remaining
Output: 2 12 false false true false 1 12
func (*Node) Compact ¶
Compact will remove unecessay nodes, reducing the capacity, returning true if node n itself should be removed.
Click to show internal directories.
Click to hide internal directories.