DirectAdd adds a single value

This commit is contained in:
Yuce Tekol 2018-09-17 17:16:03 +03:00
parent 09c24cd3be
commit 37fdd73a7f
No known key found for this signature in database
GPG key ID: CB59E46D2FB90573
2 changed files with 6 additions and 7 deletions

View file

@ -167,11 +167,9 @@ 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)
}
// DirectAdd adds a value to the bitmap by bypassing the op log.
func (b *Bitmap) DirectAdd(value uint64) bool {
return b.add(value)
}
func (b *Bitmap) add(v uint64) bool {

View file

@ -334,8 +334,9 @@ 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(0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16, 17)
bm.DirectAdd(1000000, 1000002, 1000003, 1000004, 1000005, 1000006, 1000010, 1000011, 1000012, 1000013, 1000014)
for _, b := range []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.DirectAdd(b)
}
if len(bits) != int(bm.Count()) {
t.Fatalf("count %d != %d", len(bits), bm.Count())
}