triemap

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MPL-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TrieMap

type TrieMap[V comparable] struct {
	// contains filtered or unexported fields
}

TrieMap contains an efficient trie structure of netip.Prefix that can match a netip.Addr to the associated Prefix if any and return the value associated with it of type V.

Use NewTrieMap to instantiate

Currently this is a simple TrieMap, in the future it may have compression.

See: https://vincent.bernat.ch/en/blog/2017-ipv4-route-lookup-linux

func New added in v0.6.1

func New[V comparable]() *TrieMap[V]

New[V] returns a new, properly allocated TrieMap[V]

func (*TrieMap[V]) Empty

func (t *TrieMap[V]) Empty() bool

Empty returns true if the TrieMap is empty.

func (*TrieMap[V]) Get

func (t *TrieMap[V]) Get(addr netip.Addr) (value V, contains bool)

Get returns the associated value for the matching prefix if any with contains=true, or else the default value of V and contains=false.

func (*TrieMap[V]) Insert

func (t *TrieMap[V]) Insert(prefix netip.Prefix, value V)

Insert inserts value into TrieMap by index prefix. You can later match a netip.Addr to value with Get().

func (*TrieMap[V]) Remove

func (t *TrieMap[V]) Remove(prefix netip.Prefix) bool

Remove removes the prefix from the TrieMap. Returns true if the prefix was removed, false if it was not found.

func (*TrieMap[V]) RemoveValue

func (t *TrieMap[V]) RemoveValue(value V)

RemoveValue removes all prefixes with the given value from the TrieMap.

Jump to

Keyboard shortcuts

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