Example #1
0
File: bloom.go Project: taysom/va
// 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
}
Example #2
0
File: bloom.go Project: taysom/va
// 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
}
Example #3
0
File: extend.go Project: taysom/va
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 {
	}
}