Skip to content

Commit e5a4a6f

Browse files
committed
more fixes
1 parent 2561ba1 commit e5a4a6f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

runcontainer.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,15 +2792,20 @@ func (rc *runContainer16) validate() error {
27922792
check that the number of runs < (number of distinct values) / 2
27932793
(otherwise you could use an array container)
27942794
*/
2795-
if MaxIntervalsSum <= intervalsSum {
2796-
if !(len(rc.iv) < MaxNumIntervals) {
2797-
return ErrRunIntervalSize
2798-
}
2799-
} else {
2800-
if !(2*len(rc.iv) < intervalsSum) {
2801-
return ErrRunIntervalSize
2802-
}
2803-
}
28042795

2796+
sizeAsRunContainer := runContainer16SerializedSizeInBytes(len(rc.iv))
2797+
sizeAsBitmapContainer := bitmapContainerSizeInBytes()
2798+
sizeAsArrayContainer := arrayContainerSizeInBytes(intervalsSum)
2799+
fmt.Println(sizeAsRunContainer, sizeAsBitmapContainer, sizeAsArrayContainer)
2800+
// this is always ok:
2801+
if sizeAsRunContainer < minOfInt(sizeAsBitmapContainer, sizeAsArrayContainer) {
2802+
return nil
2803+
}
2804+
if sizeAsRunContainer >= sizeAsBitmapContainer {
2805+
return ErrRunIntervalSize
2806+
}
2807+
if sizeAsRunContainer >= sizeAsArrayContainer {
2808+
return ErrRunIntervalSize
2809+
}
28052810
return nil
28062811
}

runcontainer_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,13 +2588,12 @@ func TestIntervalValidationFailing(t *testing.T) {
25882588
start := -4
25892589
for i := 0; i < MaxNumIntervals; i++ {
25902590
start += 4
2591-
end := start + 2
2591+
end := start + 1
25922592
a := newInterval16Range(uint16(start), uint16(end))
25932593
rc.iv = append(rc.iv, a)
25942594

25952595
}
25962596
assert.ErrorIs(t, rc.validate(), ErrRunIntervalSize)
2597-
25982597
// too many small runs, use array
25992598
rc = &runContainer16{}
26002599
start = -3

0 commit comments

Comments
 (0)