Documentation
¶
Overview ¶
Package trie contains a primitive implementation of the Trie data structure.
Copyright 2017 Aleksandr Bezobchuk.
Index ¶
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
}
Trie implements a thread-safe search tree that stores byte key value pairs and allows for efficient queries.
func (*Trie) GetAllKeys ¶
GetAllKeys returns all the keys that exist in the trie. Keys are retrieved by performing a DFS on the trie where at each node we keep track of the current path (key) traversed thusfar and if that node has a value. If so, the full path (key) is appended to a list. After the trie search is exhausted, the final list is returned.
func (*Trie) GetAllValues ¶
GetAllValues returns all the values that exist in the trie. Values are retrieved by performing a BFS on the trie where at each node we examine if that node has a value. If so, that value is appended to a list. After the trie search is exhausted, the final list is returned.
func (*Trie) GetPrefixKeys ¶
GetPrefixKeys returns all the keys that exist in the trie such that each key contains a specified prefix. Keys are retrieved by performing a DFS on the trie where at each node we keep track of the current path (key) and prefix traversed thusfar. If a node has a value the full path (key) is appended to a list. After the trie search is exhausted, the final list is returned.
func (*Trie) GetPrefixValues ¶
GetPrefixValues returns all the values that exist in the trie such that each key that corresponds to that value contains a specified prefix. Values are retrieved by performing a DFS on the trie where at each node we check if the prefix is exhausted or matches thusfar and the current node has a value. If the current node has a value, it is appended to a list. After the trie search is exhausted, the final list is returned.
func (*Trie) Insert ¶
Insert inserts a key value pair into the trie. If the key already exists, the value is updated. Insertion is performed by starting at the root and traversing the nodes all the way down until the key is exhausted. Once exhausted, the currNode pointer should be a pointer to the last symbol in the key and reflect the terminating node for that key value pair.