Documentation
¶
Index ¶
- type PrefixMap
- func (m *PrefixMap[T]) AncestorsOf(p netip.Prefix) *PrefixMap[T]
- func (m *PrefixMap[T]) AncestorsOfStrict(p netip.Prefix) *PrefixMap[T]
- func (m *PrefixMap[T]) Contains(p netip.Prefix) bool
- func (m *PrefixMap[T]) DescendantsOf(p netip.Prefix) *PrefixMap[T]
- func (m *PrefixMap[T]) DescendantsOfStrict(p netip.Prefix) *PrefixMap[T]
- func (m *PrefixMap[T]) Encompasses(p netip.Prefix) bool
- func (m *PrefixMap[T]) EncompassesStrict(p netip.Prefix) bool
- func (m *PrefixMap[T]) Filter(s *PrefixSet) *PrefixMap[T]
- func (m *PrefixMap[T]) Get(p netip.Prefix) (T, bool)
- func (m *PrefixMap[T]) OverlapsPrefix(p netip.Prefix) bool
- func (m *PrefixMap[T]) ParentOf(p netip.Prefix) (netip.Prefix, T, bool)
- func (m *PrefixMap[T]) ParentOfStrict(p netip.Prefix) (netip.Prefix, T, bool)
- func (m *PrefixMap[T]) RootOf(p netip.Prefix) (netip.Prefix, T, bool)
- func (m *PrefixMap[T]) RootOfStrict(p netip.Prefix) (netip.Prefix, T, bool)
- func (m *PrefixMap[T]) Size() int
- func (m *PrefixMap[T]) String() string
- func (m *PrefixMap[T]) ToMap() map[netip.Prefix]T
- type PrefixMapBuilder
- func (m *PrefixMapBuilder[T]) Filter(s *PrefixSet)
- func (m *PrefixMapBuilder[T]) Get(p netip.Prefix) (T, bool)
- func (m *PrefixMapBuilder[T]) PrefixMap() *PrefixMap[T]
- func (m *PrefixMapBuilder[T]) Remove(p netip.Prefix) error
- func (m *PrefixMapBuilder[T]) Set(p netip.Prefix, v T) error
- func (s *PrefixMapBuilder[T]) String() string
- type PrefixSet
- func (s *PrefixSet) All() iter.Seq[netip.Prefix]
- func (s *PrefixSet) AllCompact() iter.Seq[netip.Prefix]
- func (s *PrefixSet) AncestorsOf(p netip.Prefix) *PrefixSet
- func (s *PrefixSet) AncestorsOfStrict(p netip.Prefix) *PrefixSet
- func (s *PrefixSet) Contains(p netip.Prefix) bool
- func (s *PrefixSet) DescendantsOf(p netip.Prefix) *PrefixSet
- func (s *PrefixSet) DescendantsOfStrict(p netip.Prefix) *PrefixSet
- func (s *PrefixSet) Encompasses(p netip.Prefix) bool
- func (s *PrefixSet) EncompassesStrict(p netip.Prefix) bool
- func (s *PrefixSet) OverlapsPrefix(p netip.Prefix) bool
- func (s *PrefixSet) ParentOf(p netip.Prefix) (netip.Prefix, bool)
- func (s *PrefixSet) ParentOfStrict(p netip.Prefix) (netip.Prefix, bool)
- func (s *PrefixSet) Prefixes() []netip.Prefix
- func (s *PrefixSet) PrefixesCompact() []netip.Prefix
- func (s *PrefixSet) RootOf(p netip.Prefix) (netip.Prefix, bool)
- func (s *PrefixSet) RootOfStrict(p netip.Prefix) (netip.Prefix, bool)
- func (s *PrefixSet) Size() int
- func (s *PrefixSet) String() string
- type PrefixSetBuilder
- func (s *PrefixSetBuilder) Add(p netip.Prefix) error
- func (s *PrefixSetBuilder) Filter(o *PrefixSet)
- func (s *PrefixSetBuilder) Intersect(o *PrefixSet)
- func (s *PrefixSetBuilder) Merge(o *PrefixSet)
- func (s *PrefixSetBuilder) PrefixSet() *PrefixSet
- func (s *PrefixSetBuilder) Remove(p netip.Prefix) error
- func (s *PrefixSetBuilder) String() string
- func (s *PrefixSetBuilder) Subtract(o *PrefixSet)
- func (s *PrefixSetBuilder) SubtractPrefix(p netip.Prefix) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PrefixMap ¶
type PrefixMap[T any] struct { // contains filtered or unexported fields }
PrefixMap is a map of netip.Prefix to T. It is implemented as a binary radix tree.
Use PrefixMapBuilder to construct PrefixMaps.
func (*PrefixMap[T]) AncestorsOf ¶
AncestorsOf returns a PrefixMap containing all ancestors of p in m, including p itself if it has an entry.
func (*PrefixMap[T]) AncestorsOfStrict ¶
AncestorsOfStrict returns a PrefixMap containing all ancestors of p in m, excluding p itself.
func (*PrefixMap[T]) Contains ¶
Contains returns true if this map includes the exact Prefix provided.
func (*PrefixMap[T]) DescendantsOf ¶
DescendantsOf returns a PrefixMap containing all descendants of p in m, including p itself if it has an entry.
func (*PrefixMap[T]) DescendantsOfStrict ¶
DescendantsOfStrict returns a PrefixMap containing all descendants of p in m, excluding p itself.
func (*PrefixMap[T]) Encompasses ¶
Encompasses returns true if this map includes a Prefix which completely encompasses p. The encompassing Prefix may be p itself.
func (*PrefixMap[T]) EncompassesStrict ¶
EncompassesStrict returns true if this map includes a Prefix which completely encompasses p. The encompassing Prefix must be an ancestor of p, not p itself.
func (*PrefixMap[T]) Filter ¶
Filter returns a new PrefixMap containing the entries of m that are encompassed by s.
func (*PrefixMap[T]) OverlapsPrefix ¶
OverlapsPrefix returns true if this map includes a Prefix which overlaps p.
func (*PrefixMap[T]) ParentOf ¶
ParentOf returns the longest-prefix ancestor of p in m, if any. If p itself has an entry, then p's entry is returned.
func (*PrefixMap[T]) ParentOfStrict ¶
ParentOfStrict returns the longest-prefix ancestor of p in m, if any. If p has no ancestors in the map, then ParentOfStrict returns zero values and false.
func (*PrefixMap[T]) RootOf ¶
RootOf returns the shortest-prefix ancestor of p in m, if any. If p itself has an entry and has no ancestors, then p's entry is returned.
func (*PrefixMap[T]) RootOfStrict ¶
RootOfStrict returns the shortest-prefix ancestor of p in m, if any. If p has no ancestors in m, then RootOfStrict returns zero values and false.
type PrefixMapBuilder ¶
PrefixMapBuilder builds an immutable PrefixMap.
The zero value is a valid PrefixMapBuilder representing a builder with zero Prefixes.
Call PrefixMapBuilder.PrefixMap to obtain an immutable PrefixMap from a PrefixMapBuilder.
If Lazy == true, then path compression is delayed until a PrefixMap is created. The builder itself remains uncompressed. Lazy mode can dramatically reduce the time required to build a large PrefixMap.
func (*PrefixMapBuilder[T]) Filter ¶
func (m *PrefixMapBuilder[T]) Filter(s *PrefixSet)
Filter removes all Prefixes that are not encompassed by s from m.
func (*PrefixMapBuilder[T]) Get ¶
func (m *PrefixMapBuilder[T]) Get(p netip.Prefix) (T, bool)
Get returns the value associated with the exact Prefix provided, if any.
func (*PrefixMapBuilder[T]) PrefixMap ¶
func (m *PrefixMapBuilder[T]) PrefixMap() *PrefixMap[T]
PrefixMap returns an immutable PrefixMap representing the current state of m.
The builder remains usable after calling PrefixMap.
func (*PrefixMapBuilder[T]) Remove ¶
func (m *PrefixMapBuilder[T]) Remove(p netip.Prefix) error
Remove removes p from m. Only the exact Prefix provided is removed; descendants are not.
To remove entire sections of IP space at once, see PrefixMapBuilder.Filter.
func (*PrefixMapBuilder[T]) Set ¶
func (m *PrefixMapBuilder[T]) Set(p netip.Prefix, v T) error
Set associates v with p.
func (*PrefixMapBuilder[T]) String ¶
func (s *PrefixMapBuilder[T]) String() string
type PrefixSet ¶
type PrefixSet struct {
// contains filtered or unexported fields
}
PrefixSet is a set of netip.Prefix values. It is implemented as a binary radix tree.
PrefixSet offers unique functionality beyond what a PrefixMap[bool] can do. In particular, during the building stage (PrefixSetBuilder) you can combine sets in useful ways using methods like PrefixSetBuilder.Merge, PrefixSetBuilder.Intersect, and PrefixSetBuilder.Subtract.
Use PrefixSetBuilder to construct PrefixSets.
func (*PrefixSet) AllCompact ¶ added in v0.1.7
AllCompact returns an iterator over the prefixes in s that are not children of any other prefix in s.
Note: AllCompact does not merge siblings, so the result may contain complete sets of sibling prefixes, e.g. 1.2.3.0/32 and 1.2.3.1/32.
func (*PrefixSet) AncestorsOf ¶ added in v0.1.5
AncestorsOf returns a PrefixSet containing all ancestors of p in s, including p itself if it has an entry.
func (*PrefixSet) AncestorsOfStrict ¶ added in v0.1.5
AncestorsOfStrict returns a PrefixSet containing all ancestors of p in s, excluding p itself.
func (*PrefixSet) DescendantsOf ¶ added in v0.1.5
DescendantsOf returns a PrefixSet containing all descendants of p in s, including p itself if it has an entry.
func (*PrefixSet) DescendantsOfStrict ¶ added in v0.1.5
DescendantsOfStrict returns a PrefixSet containing all descendants of p in s, excluding p itself.
func (*PrefixSet) Encompasses ¶
Encompasses returns true if this set includes a Prefix which completely encompasses p. The encompassing Prefix may be p itself.
func (*PrefixSet) EncompassesStrict ¶
EncompassesStrict returns true if this set includes a Prefix which completely encompasses p. The encompassing Prefix must be an ancestor of p, not p itself.
func (*PrefixSet) OverlapsPrefix ¶
OverlapsPrefix returns true if this set includes a Prefix which overlaps p.
func (*PrefixSet) ParentOf ¶ added in v0.1.5
ParentOf returns the longest-prefix ancestor of p in s, if any. If p itself has an entry, then p's entry is returned.
func (*PrefixSet) ParentOfStrict ¶ added in v0.1.5
ParentOfStrict returns the longest-prefix ancestor of p in s, if any. If p has no ancestors in the set, then ParentOfStrict returns zero values and false.
func (*PrefixSet) PrefixesCompact ¶ added in v0.1.1
PrefixesCompact returns a slice of the Prefixes in s that are not children of other Prefixes in s.
Note: PrefixCompact does not merge siblings, so the result may contain complete sets of sibling prefixes, e.g. 1.2.3.0/32 and 1.2.3.1/32.
func (*PrefixSet) RootOf ¶ added in v0.1.5
RootOf returns the shortest-prefix ancestor of p in s, if any. If p itself has an entry and has no ancestors, then p's entry is returned.
func (*PrefixSet) RootOfStrict ¶ added in v0.1.5
RootOfStrict returns the shortest-prefix ancestor of p in s, if any. If p has no ancestors in s, then RootOfStrict returns zero values and false.
type PrefixSetBuilder ¶
type PrefixSetBuilder struct { Lazy bool // contains filtered or unexported fields }
PrefixSetBuilder builds an immutable PrefixSet.
The zero value is a valid PrefixSetBuilder representing a builder with zero Prefixes.
Call PrefixSet to obtain an immutable PrefixSet from a PrefixSetBuilder.
If Lazy == true, then path compression is delayed until a PrefixSet is created. The builder itself remains uncompressed. Lazy mode can dramatically improve performance when building large PrefixSets.
func (*PrefixSetBuilder) Add ¶
func (s *PrefixSetBuilder) Add(p netip.Prefix) error
Add adds p to s.
func (*PrefixSetBuilder) Filter ¶
func (s *PrefixSetBuilder) Filter(o *PrefixSet)
Filter removes all Prefixes that are not encompassed by o from s.
func (*PrefixSetBuilder) Intersect ¶ added in v0.1.5
func (s *PrefixSetBuilder) Intersect(o *PrefixSet)
Intersect modifies s so that it contains the intersection of the entries in s and o: to be included in the result, a Prefix must either (a) exist in both sets or (b) exist in one set and have an ancestor in the other.
func (*PrefixSetBuilder) Merge ¶ added in v0.1.5
func (s *PrefixSetBuilder) Merge(o *PrefixSet)
Merge modifies s so that it contains the union of the entries in s and o.
func (*PrefixSetBuilder) PrefixSet ¶
func (s *PrefixSetBuilder) PrefixSet() *PrefixSet
PrefixSet returns an immutable PrefixSet representing the current state of s.
The builder remains usable after calling PrefixSet.
func (*PrefixSetBuilder) Remove ¶
func (s *PrefixSetBuilder) Remove(p netip.Prefix) error
Remove removes p from s. Only the exact Prefix provided is removed; descendants are not.
To remove entire sections of IP space at once, see PrefixSetBuilder.Filter, PrefixSetBuilder.Subtract and PrefixSetBuilder.SubtractPrefix.
func (*PrefixSetBuilder) String ¶
func (s *PrefixSetBuilder) String() string
String returns a human-readable representation of s's tree structure.
func (*PrefixSetBuilder) Subtract ¶
func (s *PrefixSetBuilder) Subtract(o *PrefixSet)
Subtract modifies s so that the Prefixes in o, and all of their descendants, are removed from s, leaving behind any remaining portions of affected Prefixes. This may add elements to fill in gaps around the subtracted Prefixes.
For example, if s is {::0/126}, and we subtract ::0/128, then s will become {::1/128, ::2/127}.
func (*PrefixSetBuilder) SubtractPrefix ¶ added in v0.1.5
func (s *PrefixSetBuilder) SubtractPrefix(p netip.Prefix) error
SubtractPrefix modifies s so that p and all of its descendants are removed, leaving behind any remaining portions of affected Prefixes. This may add elements to fill in gaps around the subtracted Prefix.
For example, if s is {::0/126}, and we subtract ::0/128, then s will become {::1/128, ::2/127}.