Add some tools for analysing bloom filter use
This commit is contained in:
parent
8d87bb83a6
commit
e6c93455b5
15
internal/cmd/bloom-estimate/main.go
Normal file
15
internal/cmd/bloom-estimate/main.go
Normal 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())
|
||||||
|
}
|
30
internal/cmd/bloom-false-positives/main.go
Normal file
30
internal/cmd/bloom-false-positives/main.go
Normal 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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user