1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-17 16:12:42 +08:00

fix error

This commit is contained in:
2024-04-11 10:45:33 +08:00
parent a83ccf7c00
commit 2d851d4872
2 changed files with 9 additions and 6 deletions

View File

@ -5,7 +5,6 @@ import (
"math"
"github.com/charlienet/go-mixed/bytesconv"
"github.com/charlienet/go-mixed/expr"
"github.com/charlienet/go-mixed/hash"
"github.com/charlienet/go-mixed/redis"
)
@ -58,10 +57,7 @@ func New(expectedInsertions uint, fpp float64, opts ...option) *BloomFilter {
bf := &BloomFilter{
bits: bits,
funcs: k,
store: expr.Ternary[bitStore](
opt.redisClient == nil,
newMemStore(bits),
newRedisStore(opt.redisClient, opt.redisKey, bits)),
store: createBitStore(opt, bits),
}
return bf
@ -104,6 +100,14 @@ func (bf *BloomFilter) Clear() {
bf.store.Clear()
}
func createBitStore(opt *bloomOptions, bits uint) bitStore {
if opt.redisClient != nil {
return newRedisStore(opt.redisClient, opt.redisKey, bits)
}
return newMemStore(bits)
}
// 计算优化的位图长度,
// n 期望放置元素数量,
// p 预期的误判概率

View File

@ -17,7 +17,6 @@ func newMemStore(size uint) *memStore {
return &memStore{
size: size,
set: bitset.New(size),
lock: locker.NewRWLocker(),
}
}