Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultVisitor ¶
type DefaultVisitor struct{}
Default visitor that performs a nop traversal. Override to implement a subset of the visitor methods.
func (*DefaultVisitor) VisitNode ¶
func (*DefaultVisitor) VisitNode(key string, node *PathTrieNode) bool
func (*DefaultVisitor) VisitVal ¶
func (*DefaultVisitor) VisitVal(val *interface{}) bool
type PathTrie ¶
type PathTrie struct { Trie PathTrieMap `json:"trie"` PathSeparator string `json:"path_separator"` }
func NewWithPathSeparator ¶
Create a PathTrie with a user-supplied path separator.
func (*PathTrie) Apply ¶
Apply visitor to this PathTrie. Returns true if traversal finishes, false otherwise.
func (*PathTrie) Insert ¶
Insert val at path, with path segments separated by PathSeparator. Returns true if a new node was created, false if an existing node was overwritten.
If path starts with PathSeparator, the first PathSeparator is disregarded, e.g. "/foo/bar" does not cause the key in the top-level map to be "".
func (*PathTrie) InsertMerge ¶
func (pt *PathTrie) InsertMerge(path string, val interface{}, merge ValueMergeFunc) bool
Insert val at path, with path segments separated by PathSeparator. Returns true if a new node was created, false if an existing node was overwritten.
The merge function is responsible for updating the existing value with the new value.
func (*PathTrie) Merge ¶
func (pt *PathTrie) Merge(other *PathTrie, merge ValueMergeFunc)
Merge another PathTrie into this one. Values along the same paths are merged using the merge function.
type PathTrieMap ¶
type PathTrieMap map[string]*PathTrieNode
type PathTrieNode ¶
type PathTrieNode struct { Children PathTrieMap `json:"children,omitempty"` // Number of nodes in this subtree with non-null vals. Includes this node. Count int `json:"count"` // Name of the path segment corresponding to this node. E.g. if this node // represents /v1/foo/bar, the name would be "bar" (and the prefix would // be "/v1/foo/bar"). Name string `json:"name"` // The prefix includes the node's name and uniquely identifies the node in // the tree. Prefix string `json:"prefix"` // Payload for the node. Val interface{} `json:"val"` }
type ValueMergeFunc ¶
type ValueMergeFunc func(existing, new *interface{})