Skip to content

Commit

Permalink
Merge pull request #441 from RoaringBitmap/issue440
Browse files Browse the repository at this point in the history
fix: make RunOptimize idempotent
  • Loading branch information
lemire authored Aug 2, 2024
2 parents e4aecda + 07eef0b commit bbff6e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion arraycontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ func (ac *arrayContainer) toEfficientContainer() container {
card := ac.getCardinality()
sizeAsArrayContainer := arrayContainerSizeInBytes(card)

if sizeAsRunContainer <= minOfInt(sizeAsBitmapContainer, sizeAsArrayContainer) {
if sizeAsRunContainer < minOfInt(sizeAsBitmapContainer, sizeAsArrayContainer) {
return newRunContainer16FromArray(ac)
}
if card <= arrayDefaultMaxSize {
Expand Down
2 changes: 1 addition & 1 deletion bitmapcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ func (bc *bitmapContainer) toEfficientContainer() container {
card := bc.getCardinality()
sizeAsArrayContainer := arrayContainerSizeInBytes(card)

if sizeAsRunContainer <= minOfInt(sizeAsBitmapContainer, sizeAsArrayContainer) {
if sizeAsRunContainer < minOfInt(sizeAsBitmapContainer, sizeAsArrayContainer) {
return newRunContainer16FromBitmapContainer(bc)
}
if card <= arrayDefaultMaxSize {
Expand Down
12 changes: 12 additions & 0 deletions roaring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ import (
"github.com/stretchr/testify/require"
)

func TestIssue440(t *testing.T) {
a := NewBitmap()
a.AddMany([]uint32{1, 2, 3})
a.RunOptimize()
b1, err := a.MarshalBinary()
require.NoError(t, err)
a.RunOptimize()
b2, err := a.MarshalBinary()
require.NoError(t, err)
require.Equal(t, b1, b2)
}

func checkValidity(t *testing.T, rb *Bitmap) {
t.Helper()

Expand Down

0 comments on commit bbff6e9

Please sign in to comment.