path_trie

package
v0.0.0-...-f1bff1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 1 Imported by: 2

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 New

func New() PathTrie

Create a PathTrie with "/" as the path separator.

func NewWithPathSeparator

func NewWithPathSeparator(pathSeparator string) PathTrie

Create a PathTrie with a user-supplied path separator.

func (*PathTrie) Apply

func (pt *PathTrie) Apply(visitor Visitor) bool

Apply visitor to this PathTrie. Returns true if traversal finishes, false otherwise.

func (*PathTrie) Insert

func (pt *PathTrie) Insert(path string, val interface{}) 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.

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{})

type Visitor

type Visitor interface {
	VisitNode(key string, node *PathTrieNode) bool
	VisitVal(val *interface{}) bool
}

PathTrie visitor. Each method is applied to each PathTrie node and non-nil value. Returning false aborts the traversal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL