lib/logstorage: delete unused function - bloomfilter.containsAny

This commit is contained in:
Aliaksandr Valialkin 2024-09-05 16:21:06 +02:00
parent 2dd845fa53
commit 49e57ea80e
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 1 additions and 37 deletions

View file

@ -120,37 +120,6 @@ func (bf *bloomFilter) containsAll(tokens []string) bool {
return true
}
// containsAny returns true if bf contains at least a single token from the given tokens.
func (bf *bloomFilter) containsAny(tokens []string) bool {
bits := bf.bits
if len(bits) == 0 {
return true
}
maxBits := uint64(len(bits)) * 64
var buf [8]byte
hp := (*uint64)(unsafe.Pointer(&buf[0]))
nextToken:
for _, token := range tokens {
*hp = xxhash.Sum64(bytesutil.ToUnsafeBytes(token))
for i := 0; i < bloomFilterHashesCount; i++ {
hi := xxhash.Sum64(buf[:])
(*hp)++
idx := hi % maxBits
i := idx / 64
j := idx % 64
mask := uint64(1) << j
w := bits[i]
if (w & mask) == 0 {
// The token is missing. Check the next token
continue nextToken
}
}
// It is likely the token exists in the bloom filter
return true
}
return false
}
func getBloomFilter() *bloomFilter {
v := bloomFilterPool.Get()
if v == nil {

View file

@ -14,11 +14,6 @@ func TestBloomFilter(t *testing.T) {
if err := bf.unmarshal(data); err != nil {
t.Fatalf("unexpected error when unmarshaling bloom filter: %s", err)
}
for _, token := range tokens {
if !bf.containsAny([]string{token}) {
t.Fatalf("bloomFilterContains must return true for the added token %q", token)
}
}
if !bf.containsAll(tokens) {
t.Fatalf("bloomFilterContains must return true for the added tokens")
}
@ -72,7 +67,7 @@ func TestBloomFilterFalsePositive(t *testing.T) {
falsePositives := 0
for i := range tokens {
token := fmt.Sprintf("non-existing-token_%d", i)
if bf.containsAny([]string{token}) {
if bf.containsAll([]string{token}) {
falsePositives++
}
}