string_tree

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: BSD-2-Clause Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterFunc

type FilterFunc func(payload string) bool

FilterFunc is called on each result to see if it belongs in the resulting set

type MatchesFunc

type MatchesFunc func(payload string, val string) bool

MatchesFunc is called to check if tag data matches the input value

type TreeIteratorV4 added in v1.1.0

type TreeIteratorV4 struct {
	// contains filtered or unexported fields
}

TreeIteratorV4 is a stateful iterator over a tree.

func (*TreeIteratorV4) Address added in v1.1.0

func (iter *TreeIteratorV4) Address() patricia.IPv4Address

Address returns the current IP address for the iterator.

func (*TreeIteratorV4) Delete added in v1.2.1

func (iter *TreeIteratorV4) Delete(matchFunc MatchesFunc, matchVal string) int

Delete a tag from the current node if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - use DeleteWithBuffer if you can reuse slices, to cut down on allocations

func (*TreeIteratorV4) DeleteWithBuffer added in v1.2.1

func (iter *TreeIteratorV4) DeleteWithBuffer(buf []string, matchFunc MatchesFunc, matchVal string) int

DeleteWithBuffer a tag from the current node if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - uses input slice to reduce allocations

func (*TreeIteratorV4) Next added in v1.1.0

func (iter *TreeIteratorV4) Next() bool

Next jumps to the next element of a tree. It returns false if there is none.

func (*TreeIteratorV4) Tags added in v1.1.0

func (iter *TreeIteratorV4) Tags() []string

Tags returns the current tags for the iterator. This is not a copy and the result should not be used outside the iterator.

func (*TreeIteratorV4) TagsWithBuffer added in v1.2.1

func (iter *TreeIteratorV4) TagsWithBuffer(ret []string) []string

TagsWithBuffer returns the current tags for the iterator. To avoid allocation, it uses the provided buffer.

type TreeIteratorV6 added in v1.1.0

type TreeIteratorV6 struct {
	// contains filtered or unexported fields
}

TreeIteratorV6 is a stateful iterator over a tree.

func (*TreeIteratorV6) Address added in v1.1.0

func (iter *TreeIteratorV6) Address() patricia.IPv6Address

Address returns the current IP address for the iterator.

func (*TreeIteratorV6) Delete added in v1.2.1

func (iter *TreeIteratorV6) Delete(matchFunc MatchesFunc, matchVal string) int

Delete a tag from the current node if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - use DeleteWithBuffer if you can reuse slices, to cut down on allocations

func (*TreeIteratorV6) DeleteWithBuffer added in v1.2.1

func (iter *TreeIteratorV6) DeleteWithBuffer(buf []string, matchFunc MatchesFunc, matchVal string) int

DeleteWithBuffer a tag from the current node if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - uses input slice to reduce allocations

func (*TreeIteratorV6) Next added in v1.1.0

func (iter *TreeIteratorV6) Next() bool

Next jumps to the next element of a tree. It returns false if there is none.

func (*TreeIteratorV6) Tags added in v1.1.0

func (iter *TreeIteratorV6) Tags() []string

Tags returns the current tags for the iterator. This is not a copy and the result should not be used outside the iterator.

func (*TreeIteratorV6) TagsWithBuffer added in v1.2.1

func (iter *TreeIteratorV6) TagsWithBuffer(ret []string) []string

TagsWithBuffer returns the current tags for the iterator. To avoid allocation, it uses the provided buffer.

type TreeV4

type TreeV4 struct {
	// contains filtered or unexported fields
}

TreeV4 is an IP Address patricia tree

func NewTreeV4

func NewTreeV4() *TreeV4

NewTreeV4 returns a new Tree

func (*TreeV4) Add

func (t *TreeV4) Add(address patricia.IPv4Address, tag string, matchFunc MatchesFunc) (bool, int)

Add adds a tag to the tree - if matchFunc is non-nil, it will be used to ensure uniqueness at this node - returns whether the tag count at this address was increased, and how many tags at this address

func (*TreeV4) AddOrUpdate added in v1.2.1

func (t *TreeV4) AddOrUpdate(address patricia.IPv4Address, tag string, matchFunc MatchesFunc, updateFunc UpdatesFunc) (bool, int)

AddOrUpdate adds a tag to the tree or update it if it already exists - if matchFunc is non-nil, it will be used to ensure uniqueness at this node - returns whether the tag count at this address was increased, and how many tags at this address

func (*TreeV4) Clone

func (t *TreeV4) Clone() *TreeV4

Clone creates an identical copy of the tree - Note: the items in the tree are not deep copied

func (*TreeV4) CountTags

func (t *TreeV4) CountTags() int

CountTags iterates through the tree, counting the number of tags - note: unused nodes will have TagCount==0

func (*TreeV4) Delete

func (t *TreeV4) Delete(address patricia.IPv4Address, matchFunc MatchesFunc, matchVal string) int

Delete a tag from the tree if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - use DeleteWithBuffer if you can reuse slices, to cut down on allocations

func (*TreeV4) DeleteWithBuffer

func (t *TreeV4) DeleteWithBuffer(buf []string, address patricia.IPv4Address, matchFunc MatchesFunc, matchVal string) int

DeleteWithBuffer a tag from the tree if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - uses input slice to reduce allocations

func (*TreeV4) FindDeepestTag

func (t *TreeV4) FindDeepestTag(address patricia.IPv4Address) (bool, string)

FindDeepestTag finds a tag at the deepest level in the tree, representing the closest match. - if that target node has multiple tags, the first in the list is returned

func (*TreeV4) FindDeepestTags

func (t *TreeV4) FindDeepestTags(address patricia.IPv4Address) (bool, []string)

FindDeepestTags finds all tags at the deepest level in the tree, representing the closest match - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations

func (*TreeV4) FindDeepestTagsAppend

func (t *TreeV4) FindDeepestTagsAppend(ret []string, address patricia.IPv4Address) (bool, []string)

FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match - appends results to the input slice

func (*TreeV4) FindDeepestTagsWithFilter added in v1.2.1

func (t *TreeV4) FindDeepestTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) (bool, []string)

FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations - returns true regardless of the result of the filtering function

func (*TreeV4) FindDeepestTagsWithFilterAppend added in v1.2.1

func (t *TreeV4) FindDeepestTagsWithFilterAppend(ret []string, address patricia.IPv4Address, filterFunc FilterFunc) (bool, []string)

FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match - appends results to the input slice - returns true regardless of the result of the filtering function

func (*TreeV4) FindTags

func (t *TreeV4) FindTags(address patricia.IPv4Address) []string

FindTags finds all matching tags for given address - use FindTagsAppend if you can reuse slices, to cut down on allocations

func (*TreeV4) FindTagsAppend

func (t *TreeV4) FindTagsAppend(ret []string, address patricia.IPv4Address) []string

FindTagsAppend finds all matching tags for given address and appends them to ret

func (*TreeV4) FindTagsWithFilter

func (t *TreeV4) FindTagsWithFilter(address patricia.IPv4Address, filterFunc FilterFunc) []string

FindTagsWithFilter finds all matching tags that passes the filter function - use FindTagsWithFilterAppend if you can reuse slices, to cut down on allocations

func (*TreeV4) FindTagsWithFilterAppend

func (t *TreeV4) FindTagsWithFilterAppend(ret []string, address patricia.IPv4Address, filterFunc FilterFunc) []string

FindTagsWithFilterAppend finds all matching tags that passes the filter function - results are appended to the input slice

func (*TreeV4) Iterate added in v1.1.0

func (t *TreeV4) Iterate() *TreeIteratorV4

Iterate returns an iterator to find all nodes from a tree. It is important for the tree to not be modified while using the iterator.

func (*TreeV4) Set

func (t *TreeV4) Set(address patricia.IPv4Address, tag string) (bool, int)

Set the single value for a node - overwrites what's there Returns whether the tag count at this address was increased, and how many tags at this address

func (*TreeV4) SetOrUpdate added in v1.2.1

func (t *TreeV4) SetOrUpdate(address patricia.IPv4Address, tag string, updateFunc UpdatesFunc) (bool, int)

SetOrUpdate the single value for a node - overwrites what's there using updateFunc if present - returns whether the tag count at this address was increased, and how many tags at this address

type TreeV6

type TreeV6 struct {
	// contains filtered or unexported fields
}

TreeV6 is an IP Address patricia tree

func NewTreeV6

func NewTreeV6() *TreeV6

NewTreeV6 returns a new Tree

func (*TreeV6) Add

func (t *TreeV6) Add(address patricia.IPv6Address, tag string, matchFunc MatchesFunc) (bool, int)

Add adds a tag to the tree - if matchFunc is non-nil, it will be used to ensure uniqueness at this node - returns whether the tag count at this address was increased, and how many tags at this address

func (*TreeV6) AddOrUpdate added in v1.2.1

func (t *TreeV6) AddOrUpdate(address patricia.IPv6Address, tag string, matchFunc MatchesFunc, updateFunc UpdatesFunc) (bool, int)

AddOrUpdate adds a tag to the tree or update it if it already exists - if matchFunc is non-nil, it will be used to ensure uniqueness at this node - returns whether the tag count at this address was increased, and how many tags at this address

func (*TreeV6) Clone

func (t *TreeV6) Clone() *TreeV6

Clone creates an identical copy of the tree - Note: the items in the tree are not deep copied

func (*TreeV6) CountTags

func (t *TreeV6) CountTags() int

CountTags iterates through the tree, counting the number of tags - note: unused nodes will have TagCount==0

func (*TreeV6) Delete

func (t *TreeV6) Delete(address patricia.IPv6Address, matchFunc MatchesFunc, matchVal string) int

Delete a tag from the tree if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - use DeleteWithBuffer if you can reuse slices, to cut down on allocations

func (*TreeV6) DeleteWithBuffer

func (t *TreeV6) DeleteWithBuffer(buf []string, address patricia.IPv6Address, matchFunc MatchesFunc, matchVal string) int

DeleteWithBuffer a tag from the tree if it matches matchVal, as determined by matchFunc. Returns how many tags are removed - uses input slice to reduce allocations

func (*TreeV6) FindDeepestTag

func (t *TreeV6) FindDeepestTag(address patricia.IPv6Address) (bool, string)

FindDeepestTag finds a tag at the deepest level in the tree, representing the closest match. - if that target node has multiple tags, the first in the list is returned

func (*TreeV6) FindDeepestTags

func (t *TreeV6) FindDeepestTags(address patricia.IPv6Address) (bool, []string)

FindDeepestTags finds all tags at the deepest level in the tree, representing the closest match - use FindDeepestTagsAppend if you can reuse slices, to cut down on allocations

func (*TreeV6) FindDeepestTagsAppend

func (t *TreeV6) FindDeepestTagsAppend(ret []string, address patricia.IPv6Address) (bool, []string)

FindDeepestTagsAppend finds all tags at the deepest level in the tree, representing the closest match - appends results to the input slice

func (*TreeV6) FindDeepestTagsWithFilter added in v1.2.1

func (t *TreeV6) FindDeepestTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) (bool, []string)

FindDeepestTagsWithFilter finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match - use FindDeepestTagsWithFilterAppend if you can reuse slices, to cut down on allocations - returns true regardless of the result of the filtering function

func (*TreeV6) FindDeepestTagsWithFilterAppend added in v1.2.1

func (t *TreeV6) FindDeepestTagsWithFilterAppend(ret []string, address patricia.IPv6Address, filterFunc FilterFunc) (bool, []string)

FindDeepestTagsWithFilterAppend finds all tags at the deepest level in the tree, matching the provided filter, representing the closest match - appends results to the input slice - returns true regardless of the result of the filtering function

func (*TreeV6) FindTags

func (t *TreeV6) FindTags(address patricia.IPv6Address) []string

FindTags finds all matching tags for given address - use FindTagsAppend if you can reuse slices, to cut down on allocations

func (*TreeV6) FindTagsAppend

func (t *TreeV6) FindTagsAppend(ret []string, address patricia.IPv6Address) []string

FindTagsAppend finds all matching tags for given address and appends them to ret

func (*TreeV6) FindTagsWithFilter

func (t *TreeV6) FindTagsWithFilter(address patricia.IPv6Address, filterFunc FilterFunc) []string

FindTagsWithFilter finds all matching tags that passes the filter function - use FindTagsWithFilterAppend if you can reuse slices, to cut down on allocations

func (*TreeV6) FindTagsWithFilterAppend

func (t *TreeV6) FindTagsWithFilterAppend(ret []string, address patricia.IPv6Address, filterFunc FilterFunc) []string

FindTagsWithFilterAppend finds all matching tags that passes the filter function - results are appended to the input slice

func (*TreeV6) Iterate added in v1.1.0

func (t *TreeV6) Iterate() *TreeIteratorV6

Iterate returns an iterator to find all nodes from a tree. It is important for the tree to not be modified while using the iterator.

func (*TreeV6) Set

func (t *TreeV6) Set(address patricia.IPv6Address, tag string) (bool, int)

Set the single value for a node - overwrites what's there Returns whether the tag count at this address was increased, and how many tags at this address

func (*TreeV6) SetOrUpdate added in v1.2.1

func (t *TreeV6) SetOrUpdate(address patricia.IPv6Address, tag string, updateFunc UpdatesFunc) (bool, int)

SetOrUpdate the single value for a node - overwrites what's there using updateFunc if present - returns whether the tag count at this address was increased, and how many tags at this address

type UpdatesFunc added in v1.2.1

type UpdatesFunc func(payload string) string

UpdatesFunc is called to update the tag value

Jump to

Keyboard shortcuts

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