BoomFilters icon indicating copy to clipboard operation
BoomFilters copied to clipboard

Is concurrency security of the Test function ?

Open wangzhilong opened this issue 5 years ago • 0 comments

In Test function, the hash will be changed: hash.Write(data)。 So it's concurrency security?

func (b *BloomFilter) Test(data []byte) bool {
	lower, upper := hashKernel(data, b.hash)

	// If any of the K bits are not set, then it's not a member.
	for i := uint(0); i < b.k; i++ {
		if b.buckets.Get((uint(lower)+uint(upper)*i)%b.m) == 0 {
			return false
		}
	}

	return true
}

func hashKernel(data []byte, hash hash.Hash64) (uint32, uint32) {
	hash.Write(data)
	sum := hash.Sum(nil)
	hash.Reset()
	return binary.BigEndian.Uint32(sum[4:8]), binary.BigEndian.Uint32(sum[0:4])
}

wangzhilong avatar Mar 03 '20 03:03 wangzhilong