mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-12 12:46:23 +01:00
lib/logstorage: delete unused function - bloomfilter.containsAny
This commit is contained in:
parent
5763a957ef
commit
2630497e2c
@ -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 {
|
||||
|
@ -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++
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user