2
0
mirror of synced 2025-02-23 22:28:11 +00:00

Add some tools for analysing bloom filter use

This commit is contained in:
Matt Joiner 2014-12-20 10:07:41 +11:00
parent 8d87bb83a6
commit e6c93455b5
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package main
import (
"flag"
"fmt"
"github.com/willf/bloom"
)
func main() {
n := flag.Int("n", 0, "expected number of items")
falsePositiveRate := flag.Float64("fpr", 0, "false positive rate")
flag.Parse()
filter := bloom.NewWithEstimates(uint(*n), *falsePositiveRate)
fmt.Printf("m: %d, k: %d\n", filter.Cap(), filter.K())
}

View File

@ -0,0 +1,30 @@
package main
import (
"bufio"
"flag"
"fmt"
"github.com/willf/bloom"
"os"
)
func main() {
m := flag.Uint("m", 0, "")
k := flag.Uint("k", 0, "")
flag.Parse()
filter := bloom.New(*m, *k)
scanner := bufio.NewScanner(os.Stdin)
n := 0
collisions := 0
for scanner.Scan() {
if filter.TestAndAdd(scanner.Bytes()) {
collisions++
}
n++
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "error reading stdin: %s", err)
os.Exit(1)
}
fmt.Printf("collisions %d/%d (%f)\n", collisions, n, float64(collisions)/float64(n)*100)
}