Documentation ¶
Index ¶
- Variables
- type List
- func (list *List) Append(newPrefix netip.Prefix) bool
- func (list *List) Cap() int
- func (list *List) Contains(addr netip.Addr) (bool, error)
- func (list *List) Copy() *List
- func (list *List) GetPrefix(addr netip.Addr) (netip.Prefix, error)
- func (list *List) GetPrefixes() []netip.Prefix
- func (list *List) Len() int
- func (list *List) Sort()
- func (list *List) SortAndMerge()
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotSorted = errors.New("list is not sorted") ErrInvalidAddr = errors.New("addr is invalid") )
Functions ¶
This section is empty.
Types ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of netip.Prefix. It stores all netip.Prefix in one single slice and use binary search. It is suitable for large static cidr search. List converts IPv4 input netip.Prefix to IPv6 form. Therefore, all get functions that return netip.Prefix will always return a IPv6 form.
func (*List) Append ¶
Append appends new netip.Prefix to the list. This modified the list. Caller must call List.Sort() before calling List.Contains() If newPrefix is invalid, Append returns false.
func (*List) Contains ¶
Contains reports whether the list includes the given netip.Addr. See also: GetPrefix.
func (*List) GetPrefix ¶
GetPrefix get the netip.Prefix from list that includes the given netip.Addr. If list is not sorted or addr is not valid, an error will be returned. If no netip.Prefix was found, GetPrefix returns a zero netip.Prefix.
func (*List) GetPrefixes ¶
GetPrefixes returns a copy of list's inner []netip.Prefix.
func (*List) SortAndMerge ¶
func (list *List) SortAndMerge()
SortAndMerge sorts the list, removes overlapped prefixes, and merges continuous prefixes.