pathtrie

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Inspired by https://github.com/akitasoftware/akita-libs/blob/main/path_trie/path_trie.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PathToTrieNode

type PathToTrieNode map[string]*TrieNode

type PathTrie

type PathTrie struct {
	Trie          PathToTrieNode
	PathSeparator string
}

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) GetPathAndValue

func (pt *PathTrie) GetPathAndValue(path string) (string, interface{}, bool)

GetPathAndValue returns the given node full path and value, nil if node is not found.

func (*PathTrie) GetValue

func (pt *PathTrie) GetValue(path string) interface{}

GetValue returns the given node path value, nil if node is not found.

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 path was created, false if an existing path was overwritten.

func (*PathTrie) InsertMerge

func (pt *PathTrie) InsertMerge(path string, val interface{}, merge ValueMergeFunc) (isNewPath bool)

Insert val at path, with path segments separated by PathSeparator. Returns true if a new path was created, false if an existing path was overwritten.

The merge function is responsible for updating the existing value with the new value.

type TrieNode

type TrieNode struct {
	Children PathToTrieNode

	// 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 FullPath would be "/v1/foo/bar".
	Name string

	// FullPath includes the node's name and uniquely identifies the node in the tree.
	FullPath string

	// PathParamCounter counts the amount of path params in the FullPath
	PathParamCounter int

	// Value of the full path
	Value interface{}
}

type ValueMergeFunc

type ValueMergeFunc func(existing, newV *interface{})

Jump to

Keyboard shortcuts

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