An octet trie for quickly matching IPv4 addresses

Jonathan D. Storm 929c88a649 Fix bug in prefixLessThan 1 yıl önce
LICENSE 88257acd42 Rename LICENSE.MPL to LICENSE for pkg.go.dev 2 yıl önce
README.md ab6f046d48 Initial commit 2 yıl önce
go.mod 9ea9784c4d Add MPLv2 license 2 yıl önce
go.sum 9ea9784c4d Add MPLv2 license 2 yıl önce
otrie.go 929c88a649 Fix bug in prefixLessThan 1 yıl önce
otrie_test.go 9ea9784c4d Add MPLv2 license 2 yıl önce

README.md

otrie

An octet trie for quickly matching IPv4 addresses.

Example

prefixesStr := `10.255.251.48/30
10.255.251.52/30
10.51.4.0/24
10.52.4.0/24`

trie := otrie.NewOTrie()
prefixes := make([]*netaddr.NetAddr, 0, 128)
for _, l := range strings.Split(prefixesStr, "\n") {
	na, _ := netaddr.IP(l)
	prefixes = append(prefixes, na)
	_ = trie.AddPrefix(na)
}
if !trie.Overlaps(&netaddr.NetAddr{
	Address: []byte{10, 51, 4, 0},
	Length:  byte(24),
}) {
	fmt.Println("failed to match 10.51.4.0/24")
	fmt.Println(trie.Print())
}