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

1 Commits

Author SHA1 Message Date
2d851d4872 fix error 2024-04-11 10:45:33 +08:00
2 changed files with 9 additions and 6 deletions

View File

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

View File

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