github.com/panmari/cuckoofilter@v1.0.7-0.20231223155748-763d1d471ee8/example_test.go (about) 1 package cuckoo_test 2 3 import ( 4 "fmt" 5 6 cuckoo "github.com/panmari/cuckoofilter" 7 ) 8 9 func Example() { 10 cf := cuckoo.NewFilter(1000) 11 12 cf.Insert([]byte("pizza")) 13 cf.Insert([]byte("tacos")) 14 cf.Insert([]byte("tacos")) // Re-insertion is possible. 15 16 fmt.Println(cf.Lookup([]byte("pizza"))) 17 fmt.Println(cf.Lookup([]byte("missing"))) 18 19 cf.Reset() 20 fmt.Println(cf.Lookup([]byte("pizza"))) 21 // Output: 22 // true 23 // false 24 // false 25 } 26 27 func ExampleFilter_Lookup() { 28 cf := cuckoo.NewFilter(1000) 29 30 cf.Insert([]byte("pizza")) 31 cf.Insert([]byte("tacos")) 32 33 fmt.Println(cf.Lookup([]byte("pizza"))) 34 fmt.Println(cf.Lookup([]byte("missing"))) 35 // Output: 36 // true 37 // false 38 } 39 40 func ExampleFilter_Delete() { 41 cf := cuckoo.NewFilter(1000) 42 43 cf.Insert([]byte("pizza")) 44 cf.Insert([]byte("tacos")) 45 46 fmt.Println(cf.Lookup([]byte("pizza"))) 47 48 cf.Delete([]byte("pizza")) 49 fmt.Println(cf.Lookup([]byte("pizza"))) 50 // Output: 51 // true 52 // false 53 }