[skip ci]Fix golint warnings in dabloom (#9096)

Signed-off-by: Xiangyu Wang <xiangyu.wang@zilliz.com>
This commit is contained in:
Xiangyu Wang 2021-10-03 00:42:38 +08:00 committed by GitHub
parent 0b545efa4a
commit f05127e415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,10 +24,12 @@ import (
"unsafe"
)
// ScalingBloom is a scaling bloom filter that supports remove elements after added
type ScalingBloom struct {
cfilter *C.scaling_bloom_t
}
// NewScalingBloom returns a ScalingBloom object
func NewScalingBloom(capacity uint64, errorRate float64) *ScalingBloom {
sb := &ScalingBloom{
cfilter: C.new_scaling_bloom(C.uint(capacity), C.double(errorRate)),
@ -35,20 +37,24 @@ func NewScalingBloom(capacity uint64, errorRate float64) *ScalingBloom {
return sb
}
// Destroy is used to free memory of this object
func (sb *ScalingBloom) Destroy() {
C.free_scaling_bloom(sb.cfilter)
}
// Add is used to add an element to this bloom filter
func (sb *ScalingBloom) Add(key []byte, id int64) bool {
cKey := (*C.char)(unsafe.Pointer(&key[0]))
return C.scaling_bloom_add(sb.cfilter, cKey, C.size_t(len(key)), C.uint64_t(id)) == 1
}
// Remove is used to remove an element from this bloom filter
func (sb *ScalingBloom) Remove(key []byte, id int64) bool {
cKey := (*C.char)(unsafe.Pointer(&key[0]))
return C.scaling_bloom_remove(sb.cfilter, cKey, C.size_t(len(key)), C.uint64_t(id)) == 1
}
// Check returns whether a key may exist in this bloom filter
func (sb *ScalingBloom) Check(key []byte) bool {
cKey := (*C.char)(unsafe.Pointer(&key[0]))
return C.scaling_bloom_check(sb.cfilter, cKey, C.size_t(len(key))) == 1