Ejemplo n.º 1
0
// Add ...
func (d *BloomSketch) Add(values [][]byte) (bool, error) {
	success := true
	dict := make(map[string]uint)
	if d.threshold != nil {
		s, err := d.threshold.Add(values)
		success = s
		if err != nil {
			return false, err
		}
		if !d.threshold.IsFull() {
			return true, nil
		}
		values = d.threshold.Keys()
		d.threshold = nil
		if d.impl == nil {
			sketch := bloom.New(float64(d.Info.Properties.GetMaxUniqueItems()), 4.0)
			d.impl = &sketch
		}
	}

	for _, v := range values {
		dict[string(v)]++
	}
	for v := range dict {
		d.impl.Add([]byte(v))
	}
	// Fixme: return what was added and what not
	return success, nil
}
Ejemplo n.º 2
0
func (r *Reader) CalculateBloom(falsePosRate float64) error {
	i := NewIterator(r)
	bloom := bbloom.New(float64(r.Trailer.EntryCount), falsePosRate)
	ok, err := i.Next()
	for ok && err == nil {
		bloom.Add(i.Key())
		ok, err = i.Next()
	}
	r.bloom = &bloom
	return err
}
Ejemplo n.º 3
0
// Test a bloom database
func TestBloom(t *testing.T) {
	// create a bloom filter for 65536 items and 0.001 % wrong-positive ratio
	filter := bbloom.New(float64(1<<16), float64(0.00001))

	bloom, err := New(&filter)
	if err != nil {
		t.Fatal(err)
	}
	err = drivers.TestDriver(bloom)
	if err != nil {
		t.Fatal(err)
	}
}
Ejemplo n.º 4
0
// NewBloomSketch ...
func NewBloomSketch(info *datamodel.Info) (*BloomSketch, error) {
	// FIXME: We are converting from int64 to uint
	sketch := bloom.New(float64(info.Properties.GetMaxUniqueItems()), 4.0)
	d := BloomSketch{info, &sketch}
	return &d, nil
}