Skip to content

Commit d68badd

Browse files
committed
Rename Likely to Test
1 parent 682a320 commit d68badd

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func Example() {
1515
url := "https://rascal.com"
1616
blacklist.Add(url)
1717

18-
// Check for membership.
19-
if blacklist.Likely(url) {
18+
// Test for membership.
19+
if blacklist.Test(url) {
2020
fmt.Println(url, "seems to be shady.")
2121
} else {
2222
fmt.Println(url, "has not yet been added to our blacklist.")

filter.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
// Bloom filters
44
//
55
// A Bloom filter is a space-efficient probabilistic data structure
6-
// used to test set membership. A member query returns either
7-
// ”likely in set” or ”definitely not in set”. Only false positives
8-
// may occur: an element that has been added to the filter
9-
// will be identified as ”likely in set”.
6+
// used to test set membership. A member test returns either
7+
// ”likely member” or ”definitely not a member”. Only false positives
8+
// can occur: an element that has been added to the filter
9+
// will be identified as ”likely member”.
1010
//
11-
// Elements can be added, but not removed. With more elements in the set,
11+
// Elements can be added, but not removed. With more elements in the filter,
1212
// the probability of false positives increases.
1313
//
1414
// Implementation
1515
//
1616
// A full filter with a false-positives rate of 1/p uses roughly
1717
// 0.26ln(p) bytes per element and performs ⌈1.4ln(p)⌉ bit array lookups
18-
// per query:
18+
// per test:
1919
//
2020
// p bytes lookups
2121
// -------------------------
@@ -30,7 +30,7 @@
3030
// 1024 1.8 10
3131
//
3232
// This implementation is not intended for cryptographic use.
33-
// Each membership query makes a single call to a 128-bit MurmurHash3 function.
33+
// Each membership test makes a single call to a 128-bit MurmurHash3 function.
3434
// This saves on hashing without increasing the false-positives
3535
// probability as shown by Kirsch and Mitzenmacher.
3636
//
@@ -95,8 +95,8 @@ func (f *Filter) Add(s string) bool {
9595
return f.AddByte(b)
9696
}
9797

98-
// LikelyByte tells if b is a likely member of this filter.
99-
func (f *Filter) LikelyByte(b []byte) bool {
98+
// TestByte tells if b is a likely member of this filter.
99+
func (f *Filter) TestByte(b []byte) bool {
100100
h1, h2 := murmur.hash(b)
101101
trunc := uint64(len(f.data))<<shift - 1
102102
for i := f.lookups; i > 0; i-- {
@@ -110,11 +110,11 @@ func (f *Filter) LikelyByte(b []byte) bool {
110110
return true
111111
}
112112

113-
// Likely tells if s is a likely member of this filter.
114-
func (f *Filter) Likely(s string) bool {
113+
// Test tells if s is a likely member of this filter.
114+
func (f *Filter) Test(s string) bool {
115115
b := make([]byte, len(s))
116116
copy(b, s)
117-
return f.LikelyByte(b)
117+
return f.TestByte(b)
118118
}
119119

120120
// Count returns an estimate of the number of unique elements added to this filter.

filter_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ func TestFilter(t *testing.T) {
1111
for n := 0; n < 100; n++ {
1212
for p := 1; p <= 128; p *= 2 {
1313
filter := New(n, p)
14-
member := filter.Likely(s1)
14+
member := filter.Test(s1)
1515
if member {
16-
t.Errorf("Likely(s1) = %v; want false\n", member)
16+
t.Errorf("Test(s1) = %v; want false\n", member)
1717
}
1818
count := filter.Count()
1919
if count != 0 {
@@ -28,13 +28,13 @@ func TestFilter(t *testing.T) {
2828
if count != 1 {
2929
t.Errorf("Count() = %d; want 1\n", count)
3030
}
31-
member = filter.Likely(s1)
31+
member = filter.Test(s1)
3232
if !member {
33-
t.Errorf("Likely(s1) = %v; want true\n", member)
33+
t.Errorf("Test(s1) = %v; want true\n", member)
3434
}
35-
member = filter.Likely(s2)
35+
member = filter.Test(s2)
3636
if member {
37-
t.Errorf("Likely(s2) = %v; want false\n", member)
37+
t.Errorf("Test(s2) = %v; want false\n", member)
3838
}
3939

4040
member = filter.Add(s1)
@@ -78,21 +78,21 @@ func BenchmarkAddByte(b *testing.B) {
7878
}
7979
}
8080

81-
func BenchmarkLikely(b *testing.B) {
81+
func BenchmarkTest(b *testing.B) {
8282
b.StopTimer()
8383
filter := New(1<<30, 200)
8484
b.StartTimer()
8585
for i := 0; i < b.N; i++ {
86-
filter.Likely("The quick brown fox jumps over the lazy dog.")
86+
filter.Test("The quick brown fox jumps over the lazy dog.")
8787
}
8888
}
8989

90-
func BenchmarkLikelyByte(b *testing.B) {
90+
func BenchmarkTestByte(b *testing.B) {
9191
b.StopTimer()
9292
filter := New(1<<30, 200)
9393
b.StartTimer()
9494
s := []byte("The quick brown fox jumps over the lazy dog.")
9595
for i := 0; i < b.N; i++ {
96-
filter.LikelyByte(s)
96+
filter.TestByte(s)
9797
}
9898
}

0 commit comments

Comments
 (0)