Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Feb 4, 2025
1 parent 2561ba1 commit e5a4a6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 14 additions & 9 deletions runcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2792,15 +2792,20 @@ func (rc *runContainer16) validate() error {
check that the number of runs < (number of distinct values) / 2
(otherwise you could use an array container)
*/
if MaxIntervalsSum <= intervalsSum {
if !(len(rc.iv) < MaxNumIntervals) {
return ErrRunIntervalSize
}
} else {
if !(2*len(rc.iv) < intervalsSum) {
return ErrRunIntervalSize
}
}

sizeAsRunContainer := runContainer16SerializedSizeInBytes(len(rc.iv))
sizeAsBitmapContainer := bitmapContainerSizeInBytes()
sizeAsArrayContainer := arrayContainerSizeInBytes(intervalsSum)
fmt.Println(sizeAsRunContainer, sizeAsBitmapContainer, sizeAsArrayContainer)
// this is always ok:
if sizeAsRunContainer < minOfInt(sizeAsBitmapContainer, sizeAsArrayContainer) {
return nil
}
if sizeAsRunContainer >= sizeAsBitmapContainer {
return ErrRunIntervalSize
}
if sizeAsRunContainer >= sizeAsArrayContainer {
return ErrRunIntervalSize
}
return nil
}
3 changes: 1 addition & 2 deletions runcontainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2588,13 +2588,12 @@ func TestIntervalValidationFailing(t *testing.T) {
start := -4
for i := 0; i < MaxNumIntervals; i++ {
start += 4
end := start + 2
end := start + 1
a := newInterval16Range(uint16(start), uint16(end))
rc.iv = append(rc.iv, a)

}
assert.ErrorIs(t, rc.validate(), ErrRunIntervalSize)

// too many small runs, use array
rc = &runContainer16{}
start = -3
Expand Down

0 comments on commit e5a4a6f

Please sign in to comment.