Documentation ¶
Overview ¶
Package trie implements several types of performant Tries (e.g. rune-wise, path-wise).
The implementations are optimized for Get performance and to allocate 0 bytes of heap memory (i.e. garbage) per Get.
The Tries do not synchronize access (not thread-safe). A typical use case is to perform Puts and Deletes upfront to populate the Trie, then perform Gets very quickly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PathTrie ¶
type PathTrie struct {
// contains filtered or unexported fields
}
PathTrie is a trie of string keys and interface{} values. Internal nodes have nil values so stored nil values cannot be distinguished and are excluded from walks. By default, PathTrie will segment keys by forward slashes with PathSegmenter (e.g. "/a/b/c" -> "/a", "/b", "/c"). A custom StringSegmenter may be used to customize how strings are segmented into nodes. A classic trie might segment keys by rune (i.e. unicode points).
func LoadPathTrie ¶
LoadPathTrie reads a PathTrie from file (or io.Reader)
func (*PathTrie) Delete ¶
Delete removes the value associated with the given key. Returns true if a node was found for the given key. If the node or any of its ancestors becomes childless as a result, it is removed from the trie.
func (*PathTrie) Get ¶
Get returns the value stored at the given key. Returns nil for internal nodes or for nodes with a value of nil.
func (*PathTrie) Put ¶
Put inserts the value into the trie at the given key, replacing any existing items. It returns true if the put adds a new value, false if it replaces an existing value. Note that internal nodes have nil values so a stored nil value will not be distinguishable and will not be included in Walks.
func (*PathTrie) Save ¶
Save stores the trie to file in a gob format. does not store the Segmenter function
type RuneTrie ¶
type RuneTrie struct {
// contains filtered or unexported fields
}
RuneTrie is a trie of runes with string keys and interface{} values. Note that internal nodes have nil values so a stored nil value will not be distinguishable and will not be included in Walks.
func LoadRuneTrie ¶
LoadRuneTrie reads a RuneTrie from file (or any io.Reader)
func (*RuneTrie) Delete ¶
Delete removes the value associated with the given key. Returns true if a node was found for the given key. If the node or any of its ancestors becomes childless as a result, it is removed from the trie.
func (*RuneTrie) Get ¶
Get returns the value stored at the given key. Returns nil for internal nodes or for nodes with a value of nil.
func (*RuneTrie) Put ¶
Put inserts the value into the trie at the given key, replacing any existing items. It returns true if the put adds a new value, false if it replaces an existing value. Note that internal nodes have nil values so a stored nil value will not be distinguishable and will not be included in Walks.
type StringSegmenter ¶
StringSegmenter takes a string key with a starting index and returns the first segment after the start and the ending index. When the end is reached, the returned nextIndex should be -1. Implementations should NOT allocate heap memory as Trie Segmenters are called upon Gets. See PathSegmenter.