Documentation
¶
Index ¶
- Variables
- type Node
- type Tree
- func (tree *Tree) DeleteCIDRNetIP(ip net.IP, mask net.IPMask) error
- func (tree *Tree) DeleteCIDRNetIPAddr(ip netip.Addr, mask netip.Prefix) error
- func (tree *Tree) DeleteCIDRString(cidr string) error
- func (tree *Tree) DeleteCIDRb(cidr []byte) error
- func (tree *Tree) DeleteWholeRangeCIDR(cidr string) error
- func (tree *Tree) DeleteWholeRangeCIDRb(cidr []byte) error
- func (tree *Tree) FindCIDRIPNet(ipm net.IPNet) (interface{}, error)
- func (tree *Tree) FindCIDRNetIP(ip net.IP) (interface{}, error)
- func (tree *Tree) FindCIDRNetIPAddr(nip netip.Addr) (interface{}, error)
- func (tree *Tree) FindCIDRNetIPAddrV2(nip netip.Addr) (node *Node, value interface{}, err error)
- func (tree *Tree) FindCIDRNetIPAddrWithNode(nip netip.Addr) (node *Node, value interface{}, err error)
- func (tree *Tree) FindCIDRString(cidr string) (interface{}, error)
- func (tree *Tree) FindCIDRb(cidr []byte) (interface{}, error)
- func (tree *Tree) SetCIDRNetIP(ip net.IP, mask net.IPMask, val interface{}, overwrite bool) error
- func (tree *Tree) SetCIDRNetIPAddr(ip netip.Addr, mask netip.Prefix, val interface{}, overwrite bool) error
- func (tree *Tree) SetCIDRNetIPPrefix(prefix netip.Prefix, val interface{}, overwrite bool) error
- func (tree *Tree) SetCIDRString(cidr string, val interface{}, overwrite bool) error
- func (tree *Tree) SetCIDRb(cidr []byte, val interface{}, overwrite bool) error
- func (tree *Tree) WalkV4(walkFn WalkFunc) error
- func (tree *Tree) WalkV6(walkFn WalkFunc) error
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Node ¶ added in v1.0.7
type Node struct {
// contains filtered or unexported fields
}
func (*Node) GetAllParents ¶ added in v1.0.7
func (*Node) GetParent ¶ added in v1.0.7
GetParent returns the parent node of the current node. This is the first node that has a value above the current node.
func (*Node) GetTreeParent ¶ added in v1.0.7
GetTreeParent returns the parent node of the current node. This is the node that is used to traverse the tree.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree implements a radix tree for working with IP/mask. Thread safety is not guaranteed, you should choose your own style of protecting safety of operations.
func NewTree ¶
NewTree initializes a Tree and preallocates a specified number of nodes ready to store data. It creates a new Tree structure, sets up the root node, and optionally preallocates nodes based on the number of bits specified. This is useful for optimizing the tree for a certain number of entries.
func (*Tree) DeleteCIDRNetIP ¶ added in v1.0.2
DeleteCIDRNetIP removes a value associated with a net.IP and net.IPMask from the tree. It locks the tree for writing, determines if the IP is IPv4 or IPv6, and deletes the specific entry from the tree. For IPv4 addresses, it converts the IP and mask to uint32 format before deletion.
func (*Tree) DeleteCIDRNetIPAddr ¶ added in v1.0.2
DeleteCIDRNetIPAddr removes a value associated with a netip.Addr and netip.Prefix from the tree. It locks the tree for writing, determines if the IP is IPv4 or IPv6, and deletes the specific entry from the tree. For IPv4 addresses, it uses pre-computed masks from a cache for better performance.
func (*Tree) DeleteCIDRString ¶
DeleteCIDRString removes a value associated with an IP/mask from the tree. It locks the tree for writing, converts the CIDR string to bytes, and calls DeleteCIDRb.
func (*Tree) DeleteCIDRb ¶
DeleteCIDRb removes a value associated with an IP/mask from the tree using byte slices. It determines if the CIDR is IPv4 or IPv6, parses it, and deletes the specific entry from the tree.
func (*Tree) DeleteWholeRangeCIDR ¶
DeleteWholeRangeCIDR removes all values associated with IPs in the entire subnet specified by the CIDR. It locks the tree for writing, converts the CIDR string to bytes, and calls DeleteWholeRangeCIDRb.
func (*Tree) DeleteWholeRangeCIDRb ¶
DeleteWholeRangeCIDRb removes all values associated with IPs in the entire subnet specified by the CIDR using byte slices. It determines if the CIDR is IPv4 or IPv6, parses it, and deletes the entire range from the tree.
func (*Tree) FindCIDRIPNet ¶
FindCIDRIPNet finds the value associated with a given net.IPNet. It locks the tree for reading and determines if the IP is IPv4 or IPv6, then finds the corresponding entry in the tree.
func (*Tree) FindCIDRNetIP ¶
FindCIDRNetIP finds the value associated with a given net.IP. It locks the tree for reading and determines if the IP is IPv4 or IPv6, then finds the corresponding entry in the tree.
func (*Tree) FindCIDRNetIPAddr ¶
func (*Tree) FindCIDRNetIPAddrV2 ¶ added in v1.0.7
func (*Tree) FindCIDRNetIPAddrWithNode ¶ added in v1.0.7
func (*Tree) FindCIDRString ¶
FindCIDRString traverses the tree to the proper node and returns previously saved information in the longest covered IP. It locks the tree for reading, converts the CIDR string to bytes, and calls FindCIDRb.
func (*Tree) FindCIDRb ¶
FindCIDRb traverses the tree to the proper node and returns previously saved information in the longest covered IP using byte slices. It determines if the CIDR is IPv4 or IPv6, parses it, and finds the corresponding entry in the tree.
func (*Tree) SetCIDRNetIP ¶ added in v1.0.1
SetCIDRNetIP sets a value associated with a net.IP and net.IPMask in the tree, overwriting any existing value. It locks the tree for writing, determines if the IP is IPv4 or IPv6, and inserts it into the tree with overwrite enabled.
func (*Tree) SetCIDRNetIPAddr ¶ added in v1.0.1
func (tree *Tree) SetCIDRNetIPAddr(ip netip.Addr, mask netip.Prefix, val interface{}, overwrite bool) error
SetCIDRNetIPAddr sets a value associated with a netip.Addr IP and netip.Prefix mask in the tree, overwriting any existing value. It locks the tree for writing, determines if the IP is IPv4 or IPv6, and inserts it into the tree with overwrite enabled.
func (*Tree) SetCIDRNetIPPrefix ¶ added in v1.0.8
SetCIDRNetIPPrefix sets a value associated with a netip.Addr IP and netip.Prefix mask in the tree, overwriting any existing value. It locks the tree for writing, determines if the IP is IPv4 or IPv6, and inserts it into the tree with overwrite enabled.
func (*Tree) SetCIDRString ¶
SetCIDRString sets a value associated with an IP/mask in the tree, overwriting any existing value. It locks the tree for writing, converts the CIDR string to bytes, and calls SetCIDRb.
func (*Tree) SetCIDRb ¶
SetCIDRb adds a value associated with an IP/mask to the tree using byte slices. It determines if the CIDR is IPv4 or IPv6, parses it, and inserts it into the tree.