Skip to content

Commit 3bff4ad

Browse files
authored
Merge pull request #458 from RoaringBitmap/fix-457
Fix issue 457.
2 parents 1b5ad6c + 3d16864 commit 3bff4ad

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

roaring64/bsi64.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func (b *BSI) SetBigValue(columnID uint64, value *big.Int) {
9797
// If max/min values are set to zero then automatically determine bit array size
9898
if b.MaxValue == 0 && b.MinValue == 0 {
9999
minBits := value.BitLen() + 1
100+
if minBits == 1 {
101+
minBits = 2
102+
}
100103
for len(b.bA) < minBits {
101104
b.bA = append(b.bA, Bitmap{})
102105
}

roaring64/bsi64_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ func TestSetAndGetBigTimestamp(t *testing.T) {
112112
assert.Equal(t, 67, bsi.BitCount())
113113
}
114114

115+
// This tests a corner case where a zero value is set on an empty BSI. The bit count should never be zero.
116+
func TestSetInitialValueZero(t *testing.T) {
117+
bsi := NewDefaultBSI()
118+
bsi.SetBigValue(1, big.NewInt(0))
119+
assert.Equal(t, 1, bsi.BitCount())
120+
}
121+
115122
func TestRangeBig(t *testing.T) {
116123

117124
bsi := NewDefaultBSI()
@@ -262,15 +269,11 @@ func TestNewBSI(t *testing.T) {
262269
bsi = NewDefaultBSI()
263270
assert.Equal(t, 0, bsi.BitCount())
264271
bsi.SetValue(1, int64(0))
265-
assert.Equal(t, 0, bsi.BitCount())
272+
assert.Equal(t, 1, bsi.BitCount())
266273
bsi.SetValue(1, int64(-1))
267274
assert.Equal(t, 1, bsi.BitCount())
268275
}
269276

270-
func TestStuff(t *testing.T) {
271-
272-
}
273-
274277
func TestGE(t *testing.T) {
275278

276279
bsi := setup()

0 commit comments

Comments
 (0)