iptree

package
v0.0.0-...-66ceba8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 3 Imported by: 30

Documentation

Overview

Package iptree implements radix tree data structure for IPv4 and IPv6 networks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair struct {
	Key   *net.IPNet
	Value interface{}
}

Pair represents a key-value pair returned by Enumerate method.

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree is a radix tree for IPv4 and IPv6 networks.

func NewTree

func NewTree() *Tree

NewTree creates empty tree.

func (*Tree) DeleteByIP

func (t *Tree) DeleteByIP(ip net.IP) (*Tree, bool)

DeleteByIP removes node by given IP address. The method returns new tree (old one remains unaffected) and flag indicating if deletion happens indeed.

func (*Tree) DeleteByNet

func (t *Tree) DeleteByNet(n *net.IPNet) (*Tree, bool)

DeleteByNet removes subtree which is contained by given network. The method returns new tree (old one remains unaffected) and flag indicating if deletion happens indeed.

func (*Tree) Enumerate

func (t *Tree) Enumerate() chan Pair

Enumerate returns channel which is populated by key-value pairs of tree content.

func (*Tree) GetByIP

func (t *Tree) GetByIP(ip net.IP) (interface{}, bool)

GetByIP gets value for network which is equal to or contains given IP address.

func (*Tree) GetByNet

func (t *Tree) GetByNet(n *net.IPNet) (interface{}, bool)

GetByNet gets value for network which is equal to or contains given network.

func (*Tree) InplaceInsertIP

func (t *Tree) InplaceInsertIP(ip net.IP, value interface{})

InplaceInsertIP inserts (or replaces) value using given IP address as a key in current tree.

func (*Tree) InplaceInsertNet

func (t *Tree) InplaceInsertNet(n *net.IPNet, value interface{})

InplaceInsertNet inserts (or replaces) value using given network as a key in current tree.

func (*Tree) InsertIP

func (t *Tree) InsertIP(ip net.IP, value interface{}) *Tree

InsertIP inserts value using given IP address as a key. The method returns new tree (old one remains unaffected).

func (*Tree) InsertNet

func (t *Tree) InsertNet(n *net.IPNet, value interface{}) *Tree

InsertNet inserts value using given network as a key. The method returns new tree (old one remains unaffected).

func (*Tree) UpdateDescendants

func (t *Tree) UpdateDescendants(n *net.IPNet, callback UpdateDescendantsCallback)

UpdateDescendants accepts a target network (node) and a callback, and updates all the descendants of the target node if the callback returns true as its second return value

type UpdateDescendantsCallback

type UpdateDescendantsCallback func(Pair) (interface{}, bool)

Jump to

Keyboard shortcuts

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