mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/logstorage: delete unused function - bloomfilter.containsAny
This commit is contained in:
parent
2dd845fa53
commit
49e57ea80e
2 changed files with 1 additions and 37 deletions
|
@ -120,37 +120,6 @@ func (bf *bloomFilter) containsAll(tokens []string) bool {
|
||||||
return true
|
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 {
|
func getBloomFilter() *bloomFilter {
|
||||||
v := bloomFilterPool.Get()
|
v := bloomFilterPool.Get()
|
||||||
if v == nil {
|
if v == nil {
|
||||||
|
|
|
@ -14,11 +14,6 @@ func TestBloomFilter(t *testing.T) {
|
||||||
if err := bf.unmarshal(data); err != nil {
|
if err := bf.unmarshal(data); err != nil {
|
||||||
t.Fatalf("unexpected error when unmarshaling bloom filter: %s", err)
|
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) {
|
if !bf.containsAll(tokens) {
|
||||||
t.Fatalf("bloomFilterContains must return true for the added tokens")
|
t.Fatalf("bloomFilterContains must return true for the added tokens")
|
||||||
}
|
}
|
||||||
|
@ -72,7 +67,7 @@ func TestBloomFilterFalsePositive(t *testing.T) {
|
||||||
falsePositives := 0
|
falsePositives := 0
|
||||||
for i := range tokens {
|
for i := range tokens {
|
||||||
token := fmt.Sprintf("non-existing-token_%d", i)
|
token := fmt.Sprintf("non-existing-token_%d", i)
|
||||||
if bf.containsAny([]string{token}) {
|
if bf.containsAll([]string{token}) {
|
||||||
falsePositives++
|
falsePositives++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue