From 3d16864fa3a715938b3c471b16f2fa68298f08a9 Mon Sep 17 00:00:00 2001 From: "GUY.MOLINARI" Date: Tue, 5 Nov 2024 18:45:58 +0000 Subject: [PATCH] Fix issue 457. --- roaring64/bsi64.go | 3 +++ roaring64/bsi64_test.go | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/roaring64/bsi64.go b/roaring64/bsi64.go index a7e4d7fb..f459073e 100644 --- a/roaring64/bsi64.go +++ b/roaring64/bsi64.go @@ -97,6 +97,9 @@ func (b *BSI) SetBigValue(columnID uint64, value *big.Int) { // If max/min values are set to zero then automatically determine bit array size if b.MaxValue == 0 && b.MinValue == 0 { minBits := value.BitLen() + 1 + if minBits == 1 { + minBits = 2 + } for len(b.bA) < minBits { b.bA = append(b.bA, Bitmap{}) } diff --git a/roaring64/bsi64_test.go b/roaring64/bsi64_test.go index 4e0d2a5b..238b538e 100644 --- a/roaring64/bsi64_test.go +++ b/roaring64/bsi64_test.go @@ -112,6 +112,13 @@ func TestSetAndGetBigTimestamp(t *testing.T) { assert.Equal(t, 67, bsi.BitCount()) } +// This tests a corner case where a zero value is set on an empty BSI. The bit count should never be zero. +func TestSetInitialValueZero(t *testing.T) { + bsi := NewDefaultBSI() + bsi.SetBigValue(1, big.NewInt(0)) + assert.Equal(t, 1, bsi.BitCount()) +} + func TestRangeBig(t *testing.T) { bsi := NewDefaultBSI() @@ -262,15 +269,11 @@ func TestNewBSI(t *testing.T) { bsi = NewDefaultBSI() assert.Equal(t, 0, bsi.BitCount()) bsi.SetValue(1, int64(0)) - assert.Equal(t, 0, bsi.BitCount()) + assert.Equal(t, 1, bsi.BitCount()) bsi.SetValue(1, int64(-1)) assert.Equal(t, 1, bsi.BitCount()) } -func TestStuff(t *testing.T) { - -} - func TestGE(t *testing.T) { bsi := setup()