nradix

package module
v0.0.0-...-76d400a Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: MIT Imports: 5 Imported by: 0

README

nradix

Translated to Golang implementation of nginx's radix tree (allowing to store and lookup IP information)


This project is licensed under the terms of the MIT license.
Read LICENSE file for information for all notices and permissions.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNodeBusy = errors.New("Node Busy")
	ErrNotFound = errors.New("No Such Node")
	ErrBadIP    = errors.New("Bad IP address or mask")
)

Functions

This section is empty.

Types

type Tree

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

Tree implements 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

func NewTree(preallocate int) *Tree

NewTree creates Tree and preallocates (if preallocate not zero) number of nodes that would be ready to fill with data.

func (*Tree) AddCIDR

func (tree *Tree) AddCIDR(cidr string, val interface{}) error

AddCIDR adds value associated with IP/mask to the tree. Will return error for invalid CIDR or if value already exists.

func (*Tree) AddCIDRb

func (tree *Tree) AddCIDRb(cidr []byte, val interface{}) error

func (*Tree) DeleteCIDR

func (tree *Tree) DeleteCIDR(cidr string) error

DeleteCIDR removes value associated with IP/mask from the tree.

func (*Tree) DeleteCIDRb

func (tree *Tree) DeleteCIDRb(cidr []byte) error

func (*Tree) DeleteWholeRangeCIDR

func (tree *Tree) DeleteWholeRangeCIDR(cidr string) error

DeleteWholeRangeCIDR removes all values associated with IPs in the entire subnet specified by the CIDR.

func (*Tree) DeleteWholeRangeCIDRb

func (tree *Tree) DeleteWholeRangeCIDRb(cidr []byte) error

func (*Tree) FindCIDR

func (tree *Tree) FindCIDR(cidr string) (interface{}, error)

Find CIDR traverses tree to proper Node and returns previously saved information in longest covered IP.

func (*Tree) FindCIDRb

func (tree *Tree) FindCIDRb(cidr []byte) (interface{}, error)

func (*Tree) SetCIDR

func (tree *Tree) SetCIDR(cidr string, val interface{}) error

AddCIDR adds value associated with IP/mask to the tree. Will return error for invalid CIDR or if value already exists.

func (*Tree) SetCIDRb

func (tree *Tree) SetCIDRb(cidr []byte, val interface{}) error

Jump to

Keyboard shortcuts

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