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

3 Commits

Author SHA1 Message Date
54fbe8eb0a locker 2024-05-28 04:05:37 +08:00
2d851d4872 fix error 2024-04-11 10:45:33 +08:00
a83ccf7c00 config 2023-12-13 17:26:23 +08:00
3 changed files with 16 additions and 10 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,7 @@ func newMemStore(size uint) *memStore {
return &memStore{
size: size,
set: bitset.New(size),
lock: locker.NewRWLocker(),
lock: locker.RWLocker{},
}
}

View File

@ -5,11 +5,13 @@ import (
"github.com/spf13/viper"
)
type Configure interface {
GetString(string, string) string
}
type NotifyFunc func(Configure) error
type NotifyFunc func(Configure)
type Configure interface {
Load(dataId string, v any, onChanged ...NotifyFunc) error
GetString(string, string) string
GetInt(key string, defaultValue int) int
}
type conf struct {
viper *viper.Viper //