Skip to content

roaring64: keep MaxValue, MinValue and run optimization in BSI Clone - #612

Merged
lemire merged 2 commits into
masterfrom
bsi64-clone-keep-fields
Dec 5, 2026
Merged

lemire merged 2 commits into
masterfrom
bsi64-clone-keep-fields

Conversation

@lemire

@lemire lemire commented Dec 4, 2026

Copy link
Copy Markdown
Member

Bug

NewBSIRetainSet, which Clone calls, built the copy with NewDefaultBSI(). The copy therefore lost MaxValue, MinValue and the runOptimized flag:

bsi := roaring64.NewBSI(1000, -1000)
bsi.RunOptimize()
c := bsi.Clone()
c.MaxValue, c.MinValue      // 0, 0 (expected 1000, -1000)
c.HasRunCompression()       // false (expected true)

Because both bounds are zero, a clone of a fixed-width BSI becomes auto-sized: SetValue widens the clone where it would not widen the original. Losing runOptimized means that operations which run-optimize their results when the input is run-optimized (TransposeWithCounts, for example) behave differently on the clone.

Fix

Copy the three fields into the new BSI. The width was already preserved. The doc comment now says the copy keeps these settings.

Testing

TestCloneKeepsSettings covers Clone and NewBSIRetainSet:

  • The bounds, run optimization flag, width and values are kept.
  • The clone of a fixed-width BSI stays fixed-width.
  • The clone of an auto-sized BSI stays auto-sized.

It fails on master. go test ./roaring64, go vet and gofmt pass.

NewBSIRetainSet, and so Clone, built the copy with NewDefaultBSI, so the
copy lost MaxValue, MinValue and the runOptimized flag. A clone of a
fixed-width BSI became auto-sized, and SetValue could then widen the
clone where it would not widen the original. Copy the three fields.
Keep the clone settings test alongside the add benchmark.
@lemire
lemire merged commit f4f7403 into master Dec 5, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant