37 lines
608 B
Go
37 lines
608 B
Go
package bloomfilter
|
|
|
|
type Local struct {
|
|
bitmap []int
|
|
}
|
|
|
|
func (l *Local) getSite(sum uint64) (index uint64, offset uint64) {
|
|
index = sum >> 5
|
|
offset = sum & 31
|
|
|
|
return
|
|
}
|
|
|
|
func (l *Local) Create(u uint64) {
|
|
l.bitmap = make([]int, u/32+1)
|
|
}
|
|
|
|
func (l *Local) Set(uint64s []uint64) error {
|
|
for _, u := range uint64s {
|
|
index, offset := l.getSite(u)
|
|
l.bitmap[index] |= 1 << offset
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (l *Local) Get(uint64s []uint64) (bool, error) {
|
|
for _, u := range uint64s {
|
|
index, offset := l.getSite(u)
|
|
if l.bitmap[index]&(1<<offset) == 0 {
|
|
return false, nil
|
|
}
|
|
}
|
|
|
|
return true, nil
|
|
}
|