mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Adds DirectAdd function to roaring.Bitmap
This commit is contained in:
parent
55bb12a434
commit
266051dd26
2 changed files with 22 additions and 0 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue