Usage Examples
jonathan-kosgei opened this issue · 1 comments
jonathan-kosgei commented
I'm new to go and I'm trying to use this library in my code. I've gone through all the test files, open and closed issues but haven't found anything in the way of an example of how to use this.
Is it possible to show me how to;
- add a network to a tree and tag it
- check if an ip address is in a tree
Thanks!
jonathan-kosgei commented
I was able to figure this out, here's an example of how to use the bool tree;
package main
import (
"fmt"
"github.com/kentik/patricia"
"github.com/kentik/patricia/bool_tree"
)
func main() {
t := bool_tree.NewTreeV4()
ip, _, _ := patricia.ParseIPFromString("172.16.0.0/12")
a, _, _ := patricia.ParseIPFromString("172.16.0.10")
t.Set(*ip, true)
f, v, _ := t.FindDeepestTag(*a)
fmt.Printf("Value: %t\n", v)
fmt.Printf("Found: %t\n", f)
}
This will give the output;
Value: true
Found: true