mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
boom filter
This commit is contained in:
@ -39,9 +39,9 @@ func WithRedis(redis *redis.Client, key string) option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化布隆过滤器
|
// New 初始化布隆过滤器
|
||||||
// https://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
|
// https://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
|
||||||
func NewBloomFilter(expectedInsertions uint, fpp float64, opts ...option) *BloomFilter {
|
func New(expectedInsertions uint, fpp float64, opts ...option) *BloomFilter {
|
||||||
opt := &bloomOptions{}
|
opt := &bloomOptions{}
|
||||||
|
|
||||||
for _, f := range opts {
|
for _, f := range opts {
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
const ()
|
const ()
|
||||||
|
|
||||||
func TestBloom(t *testing.T) {
|
func TestBloom(t *testing.T) {
|
||||||
b := bloom.NewBloomFilter(1000, 0.03)
|
b := bloom.New(1000, 0.03)
|
||||||
|
|
||||||
for i := 0; i < 1000000; i++ {
|
for i := 0; i < 1000000; i++ {
|
||||||
b.Add(strconv.Itoa(i))
|
b.Add(strconv.Itoa(i))
|
||||||
@ -54,7 +54,7 @@ func TestRedis(t *testing.T) {
|
|||||||
Password: "123456",
|
Password: "123456",
|
||||||
})
|
})
|
||||||
|
|
||||||
bf := bloom.NewBloomFilter(10000, 0.03, bloom.WithRedis(client, "bloom:test"))
|
bf := bloom.New(10000, 0.03, bloom.WithRedis(client, "bloom:test"))
|
||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
bf.Add(strconv.Itoa(i))
|
bf.Add(strconv.Itoa(i))
|
||||||
@ -78,7 +78,7 @@ func TestRedis(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClear(t *testing.T) {
|
func TestClear(t *testing.T) {
|
||||||
bf := bloom.NewBloomFilter(1000, 0.03)
|
bf := bloom.New(1000, 0.03)
|
||||||
|
|
||||||
v := "abc"
|
v := "abc"
|
||||||
bf.Add(v)
|
bf.Add(v)
|
||||||
@ -91,7 +91,7 @@ func TestClear(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParallel(t *testing.T) {
|
func TestParallel(t *testing.T) {
|
||||||
f := bloom.NewBloomFilter(1000, 0.03)
|
f := bloom.New(1000, 0.03)
|
||||||
|
|
||||||
for i := 0; i < 10000; i++ {
|
for i := 0; i < 10000; i++ {
|
||||||
v := rand.Hex.Generate(10)
|
v := rand.Hex.Generate(10)
|
||||||
@ -104,7 +104,7 @@ func TestParallel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFilter(b *testing.B) {
|
func BenchmarkFilter(b *testing.B) {
|
||||||
f := bloom.NewBloomFilter(1000, 0.03)
|
f := bloom.New(1000, 0.03)
|
||||||
|
|
||||||
b.RunParallel(func(p *testing.PB) {
|
b.RunParallel(func(p *testing.PB) {
|
||||||
for p.Next() {
|
for p.Next() {
|
||||||
|
Reference in New Issue
Block a user