iptrie

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MagicHeader identifies ELLIO pre-computed trie format
	MagicHeader = "ELLIOTRIE"
	// FormatVersion of the trie format
	FormatVersion uint16 = 2
)

Variables

View Source
var (
	// ErrInvalidMagic indicates the file doesn't have the ELLIOTRIE header
	ErrInvalidMagic = errors.New("invalid magic header, not an ELLIOTRIE format file")
	// ErrUnsupportedVersion indicates an unsupported format version
	ErrUnsupportedVersion = errors.New("unsupported ELLIOTRIE format version")
)

Functions

This section is empty.

Types

type SerializedNode

type SerializedNode struct {
	LeftChild  uint32 // Index of left child, 0xFFFFFFFF if none
	RightChild uint32 // Index of right child, 0xFFFFFFFF if none
	Flags      uint8  // Bit 0: isEnd, Bits 1-7: depth
}

SerializedNode represents a node in the serialized trie format

type Trie

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

Trie is a binary trie for fast IP prefix lookups

func BulkLoad

func BulkLoad(prefixes []netip.Prefix) *Trie

BulkLoad creates a new trie from a list of prefixes ASSUMES: Input data is already sorted (IPv4 first, then IPv6, both in ascending order)

func LoadBinaryTrie

func LoadBinaryTrie(r io.Reader) (*Trie, int64, error)

LoadBinaryTrie loads a pre-computed trie from ELLIOTRIE format

func LoadPrecomputedTrie

func LoadPrecomputedTrie(r io.Reader) (*Trie, int64, error)

LoadPrecomputedTrie loads a pre-computed trie structure from binary format

func NewTrie

func NewTrie() *Trie

NewTrie creates a new IP trie

func (*Trie) Contains

func (t *Trie) Contains(addr netip.Addr) bool

Contains checks if an IP address is contained in any prefix in the trie

func (*Trie) ContainsUnsafe

func (t *Trie) ContainsUnsafe(addr netip.Addr) bool

ContainsUnsafe performs a lockless lookup - ONLY use when trie is read-only

func (*Trie) Count

func (t *Trie) Count() int64

Count returns the number of prefixes in the trie

func (*Trie) Insert

func (t *Trie) Insert(prefix netip.Prefix)

Insert adds a prefix to the trie

type TrieHeader

type TrieHeader struct {
	Magic      [9]byte
	Version    uint16
	Flags      uint8
	TotalNodes uint32
	IPv4Root   uint32 // Index of IPv4 root node, 0xFFFFFFFF if none
	IPv6Root   uint32 // Index of IPv6 root node, 0xFFFFFFFF if none
}

TrieHeader represents the pre-computed trie file header

type TrieNode

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

TrieNode represents a node in the binary trie

Jump to

Keyboard shortcuts

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