Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PathSegmenter ¶
PathSegmenter segments string key paths by slash separators. For example, "/a/b/c" -> ("/a", 2), ("/b", 4), ("/c", -1) in successive calls. It does not allocate any heap memory.
Types ¶
type PathTrie ¶
type PathTrie[T any] struct { // contains filtered or unexported fields }
PathTrie is a trie of string keys and T 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 NewPathTrie ¶
NewPathTrie allocates and returns a new *PathTrie.
func NewPathTrieWithConfig ¶
func NewPathTrieWithConfig[T any](config *PathTrieConfig) *PathTrie[T]
NewPathTrieWithConfig allocates and returns a new *PathTrie with the given *PathTrieConfig
func (*PathTrie[T]) 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[T]) Get ¶
Get returns the value matched by path. Returns default value for internal nodes or for nodes with a default value.
func (*PathTrie[T]) 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[T]) Walk ¶
Walk iterates over each key/value stored in the trie and calls the given walker function with the key and value. If the walker function returns an error, the walk is aborted. The traversal is depth first with no guaranteed order.
type PathTrieConfig ¶
type PathTrieConfig struct {
Segmenter StringSegmenter
}
PathTrieConfig for building a path trie with different segmenter
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.