To use the Cuckoo Filter, initialize it using cuckoo.NewFilter(capacity) where capacity is the expected number of items. You can then perform insertions, lookups, deletions, and count the current number of items.
Key methods:
InsertUnique([]byte): Adds an item to the filter.Lookup([]byte) bool: Returns true if the item is likely in the set.Delete([]byte) bool: Removes an item from the set.Count() uint: Returns the number of items currently in the filter.Reset(): Clears the filter.
package main
import "fmt"
import cuckoo "github.com/seiflotfy/cuckoofilter"
func main() {
cf := cuckoo.NewFilter(1000)
cf.InsertUnique([]byte("geeky ogre"))
// Lookup a string (and it a miss) if it exists in the cuckoofilter
cf.Lookup([]byte("hello"))
count := cf.Count()
fmt.Println(count) // count == 1
// Delete a string (and it a miss)
cf.Delete([]byte("hello"))
count = cf.Count()
fmt.Println(count) // count == 1
// Delete a string (a hit)
cf.Delete([]byte("geeky ogre"))
count = cf.Count()
fmt.Println(count) // count == 0
cf.Reset() // reset
}