mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
fix error
This commit is contained in:
@ -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 预期的误判概率
|
||||||
|
@ -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(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user