Documentation ¶
Overview ¶
Ternary Search Tree
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
An empty value of this type can be used to Put values.
func (*Trie) Get ¶
Get returns the value of the desired key, or nil if the key wasn't found.
Complexity: O(m) worst case
Example ¶
t := &Trie{} t.Put("hello", "world") fmt.Println(t.Get("hello").(string)) fmt.Println(t.Get("non-existant"))
Output: world <nil>
func (*Trie) LongestPrefix ¶
LongestPrefix returns the longest key that has a prefix in common with the key. If no match is found, "" is returned.
Complexity: O(m) worst case
Example ¶
t := &Trie{} t.Put("Hello", "World") t.Put("Hello, brother", "World") t.Put("Hello, bob", "World") t.LongestPrefix("Hello, brandon") // "Hello" t.LongestPrefix("Hel") // "" t.LongestPrefix("Hello") // "Hello"
Output:
func (*Trie) Put ¶
Put adds a key/value pair to the Trie.
Complexity: O(m)
Example ¶
t := &Trie{} t.Put("hello", "world") t.Put("hello", "world") // does the same thing fmt.Println(t.Get("hello")) t.Put("1", 1) fmt.Println(t.Get("1").(int))
Output: world 1
func (*Trie) Wildcard ¶
Wildcard Returns a sorted slice with matches for the key. The wildcard characters that match any character are '*' and '.'. If no match is found, an empty slice is returned.
Complexity: O(n) worst case
Example ¶
t := &Trie{} t.Put("Hello", "World") t.Put("Hilly", "World") t.Put("Hello, bob", "World") t.Wildcard("H*ll.") // []string{"Hello", "Hilly"} t.Wildcard("Hel") // []string(nil)
Output:
Click to show internal directories.
Click to hide internal directories.