-
Notifications
You must be signed in to change notification settings - Fork 7
/
bloomfilter.go
43 lines (38 loc) · 1.2 KB
/
bloomfilter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2019 IoTeX
// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache
// License 2.0 that can be found in the LICENSE file.
package bloom
import (
"github.com/pkg/errors"
)
type (
// BloomFilter interface
BloomFilter interface {
// Add key into bloom filter
Add([]byte)
// Exist checks if a key is in bloom filter
Exist([]byte) bool
// Bytes returns the bytes of bloom filter
Bytes() []byte
}
)
// NewBloomFilter returns a new bloom filter
func NewBloomFilter(m, h uint) (BloomFilter, error) {
switch m {
case 2048:
return newBloom2048(h)
default:
return nil, errors.Errorf("bloom filter size %d not supported", m)
}
}
// BloomFilterFromBytes constructs a bloom filter from bytes
func BloomFilterFromBytes(b []byte, m, h uint) (BloomFilter, error) {
switch m {
case 2048:
return bloom2048FromBytes(b, h)
default:
return nil, errors.Errorf("bloom filter size %d not supported", m)
}
}