Adds DirectAdd function to roaring.Bitmap

This commit is contained in:
Yuce Tekol 2018-09-17 16:25:34 +03:00
parent 55bb12a434
commit 266051dd26
No known key found for this signature in database
GPG key ID: CB59E46D2FB90573
2 changed files with 22 additions and 0 deletions

View file

@ -167,6 +167,13 @@ func (b *Bitmap) Add(a ...uint64) (changed bool, err error) {
return changed, nil
}
// DirectAdd adds values to the bitmap by bypassing the op log.
func (b *Bitmap) DirectAdd(values []uint64) {
for _, value := range values {
b.add(value)
}
}
func (b *Bitmap) add(v uint64) bool {
cont := b.Containers.GetOrCreate(highbits(v))
return cont.add(lowbits(v))

View file

@ -331,6 +331,21 @@ func TestBitmap_ArrayCountRange(t *testing.T) {
}
}
func TestBitmap_DirectAdd(t *testing.T) {
bits := []uint64{0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 1000000, 1000002, 1000003, 1000004, 1000005, 1000006, 1000010, 1000011, 1000012, 1000013, 1000014}
bm := roaring.NewBitmap()
bm.DirectAdd([]uint64{0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 17})
bm.DirectAdd([]uint64{1000000, 1000002, 1000003, 1000004, 1000005, 1000006, 1000010, 1000011, 1000012, 1000013, 1000014})
if len(bits) != int(bm.Count()) {
t.Fatalf("count %d != %d", len(bits), bm.Count())
}
for _, bit := range bits {
if !bm.Contains(bit) {
t.Fatalf("%d should be in the bitmap", bit)
}
}
}
func TestBitmap_RunCountRange(t *testing.T) {
bm0 := roaring.NewFileBitmap(0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 17, 1000000, 1000002, 1000003, 1000004, 1000005, 1000006, 1000010, 1000011, 1000012, 1000013, 1000014)
bm0.Optimize() // convert to runs