Skip to content

Tip #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove counting example
  • Loading branch information
korthaj committed Jun 2, 2017
commit 641687edc23f9946ca7044069defa3e7faf952fc
25 changes: 0 additions & 25 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bloom_test
import (
"fmt"
"github.com/yourbasic/bloom"
"math/rand"
"strconv"
)

Expand All @@ -26,30 +25,6 @@ func Example_basics() {
// Output: https://rascal.com seems to be shady.
}

// Estimate the number of false positives.
func Example_falsePositives() {
// Create a Bloom filter with room for n elements
// at a false-positives rate less than 1/p.
n, p := 10000, 100
filter := bloom.New(n, p)

// Add n random strings.
for i := 0; i < n; i++ {
filter.Add(strconv.Itoa(rand.Int()))
}

// Do n random lookups and count the (mostly accidental) hits.
// It shouldn't be much more than n/p, and hopefully less.
count := 0
for i := 0; i < n; i++ {
if filter.Test(strconv.Itoa(rand.Int())) {
count++
}
}
fmt.Println(count, "mistakes were made.")
// Output: 26 mistakes were made.
}

// Compute the union of two filters.
func ExampleFilter_Union() {
// Create two Bloom filters, each with room for 1000 elements
Expand Down
5 changes: 5 additions & 0 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
// The internal data representation is different for big-endian
// and little-endian machines.
//
// Typical use case
//
// The Basics example contains a typcial use case:
// a blacklist of shady websites.
//
package bloom

import (
Expand Down