Documentation ¶
Index ¶
- type Tree
- func (t *Tree[T]) DeletePrefix(prefix netip.Prefix) bool
- func (t *Tree[T]) DepthFirstWalk(isIPv6 bool, fn WalkFn[T])
- func (t *Tree[T]) GetHostIPPrefixMatches(ip netip.Addr) map[netip.Prefix]T
- func (t *Tree[T]) GetPrefix(prefix netip.Prefix) (T, bool)
- func (t *Tree[T]) InsertPrefix(prefix netip.Prefix, v T) bool
- func (t *Tree[T]) Len(isV6 bool) int
- func (t *Tree[T]) LongestPrefixMatch(prefix netip.Prefix) (netip.Prefix, T, bool)
- func (t *Tree[T]) ShortestPrefixMatch(prefix netip.Prefix) (netip.Prefix, T, bool)
- func (t *Tree[T]) TopLevelPrefixes(isIPv6 bool) map[string]T
- func (t *Tree[T]) WalkPath(path netip.Prefix, fn WalkFn[T])
- func (t *Tree[T]) WalkPrefix(prefix netip.Prefix, fn WalkFn[T])
- type WalkFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tree ¶
type Tree[T any] struct { // contains filtered or unexported fields }
Tree is a radix tree for IPv4 and IPv6 networks.
func (*Tree[T]) DeletePrefix ¶
DeletePrefix delete the exact prefix and return true if it existed.
func (*Tree[T]) DepthFirstWalk ¶
DepthFirstWalk is used to walk the tree of the corresponding IP family
func (*Tree[T]) GetHostIPPrefixMatches ¶
GetHostIPPrefixMatches returns the list of prefixes that contain the specified Host IP. An IP is considered a Host IP if is within the subnet range and is not the network address or, if IPv4, the broadcast address (RFC 1878).
func (*Tree[T]) GetPrefix ¶
GetPrefix returns the stored value and true if the exact prefix exists in the tree.
func (*Tree[T]) InsertPrefix ¶
InsertPrefix is used to add a new entry or update an existing entry. Returns true if updated.
func (*Tree[T]) LongestPrefixMatch ¶
LongestPrefixMatch returns the longest prefix match, the stored value and true if exist. For example, considering the following prefixes 192.168.20.16/28 and 192.168.0.0/16, when the address 192.168.20.19/32 is looked up it will return 192.168.20.16/28.
func (*Tree[T]) ShortestPrefixMatch ¶
ShortestPrefixMatch returns the shortest prefix match, the stored value and true if exist. For example, considering the following prefixes 192.168.20.16/28 and 192.168.0.0/16, when the address 192.168.20.19/32 is looked up it will return 192.168.0.0/16.
func (*Tree[T]) TopLevelPrefixes ¶
TopLevelPrefixes is used to return a map with all the Top Level prefixes from the corresponding IP family and its values. For example, if the tree contains entries for 10.0.0.0/8, 10.1.0.0/16, and 192.168.0.0/16, this will return 10.0.0.0/8 and 192.168.0.0/16.