Skip to content

Commit a7ec2b7

Browse files
authored
Merge pull request #86 from bits-and-blooms/dlemire/clarifying_test_and_add
This improves slightly the documentation.
2 parents 658f139 + fb05ab3 commit a7ec2b7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

bloom.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ func (f *BloomFilter) TestLocations(locs []uint64) bool {
225225
return true
226226
}
227227

228-
// TestAndAdd is the equivalent to calling Test(data) then Add(data).
228+
// TestAndAdd is equivalent to calling Test(data) then Add(data).
229+
// The filter is written to unconditionnally: even if the element is present,
230+
// the corresponding bits are still set. See also TestOrAdd.
229231
// Returns the result of Test.
230232
func (f *BloomFilter) TestAndAdd(data []byte) bool {
231233
present := true
@@ -241,12 +243,15 @@ func (f *BloomFilter) TestAndAdd(data []byte) bool {
241243
}
242244

243245
// TestAndAddString is the equivalent to calling Test(string) then Add(string).
246+
// The filter is written to unconditionnally: even if the string is present,
247+
// the corresponding bits are still set. See also TestOrAdd.
244248
// Returns the result of Test.
245249
func (f *BloomFilter) TestAndAddString(data string) bool {
246250
return f.TestAndAdd([]byte(data))
247251
}
248252

249-
// TestOrAdd is the equivalent to calling Test(data) then if not present Add(data).
253+
// TestOrAdd is equivalent to calling Test(data) then if not present Add(data).
254+
// If the element is already in the filter, then the filter is unchanged.
250255
// Returns the result of Test.
251256
func (f *BloomFilter) TestOrAdd(data []byte) bool {
252257
present := true
@@ -262,6 +267,7 @@ func (f *BloomFilter) TestOrAdd(data []byte) bool {
262267
}
263268

264269
// TestOrAddString is the equivalent to calling Test(string) then if not present Add(string).
270+
// If the string is already in the filter, then the filter is unchanged.
265271
// Returns the result of Test.
266272
func (f *BloomFilter) TestOrAddString(data string) bool {
267273
return f.TestOrAdd([]byte(data))

0 commit comments

Comments
 (0)