Beispiel #1
0
// MakeBloom creates a bloom filter that has m excected number of entries
func MakeBloom(m uint64) *Bloom {
	bl := new(Bloom)
	bl.shift = nextPowerOf2(m * k)
	bl.filter = bitmap.Make((1 << bl.shift) * k)
	bl.mask = ((1 << bl.shift) - 1)
	bug.Px("shift", bl.shift)
	bug.Px("mask", bl.mask)
	return bl
}
Beispiel #2
0
// MayExist returns true if the byte slice may already exist
func (bl *Bloom) MayExist(key []byte) bool {
	crc := hash(key)
	for i := 0; i < 64/int(bl.shift); i++ {
		if bl.filter.IsClear(crc & bl.mask) {
			bug.Pr(string(key))
			bug.Px("i", i)
			return false
		}
		crc >>= bl.shift
	}
	return true
}
Beispiel #3
0
func Insert(key int, val int) {
	bug.Where()
	mask := ((1 << Depth) - 1)
	i := (key >> (maxLeavesLb - Depth - 1)) & mask
	bug.Px("mask", mask)
	leaf := Leaves[i]
	if leaf == nil {
		leaf = &Leaf{}
		Leaves[i] = leaf
	}
	if leaf.n < maxRecords {
		leaf.rec[leaf.n] = Record{key, val}
		leaf.n++
	} else {
	}
}