Skip to content

Commit

Permalink
bug fix on arraycontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
bstrausser committed Jun 3, 2024
1 parent e7d518c commit 8828ae8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions arraycontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,25 @@ func (ac *arrayContainer) nextAbsentValue(target uint16) int {
// Ex: target=5 ac=[1,2,3,4,6,7] returns 6
// Ex: target=6 ac=[1,2,3,4,6,7] returns 6
func (ac *arrayContainer) nextValue(target uint16) int {
cardinality := len(ac.content)
if cardinality == 0 {
return -1
}

if target < ac.minimum() {
return -1
}
if target > ac.maximum() {
return -1
}

result := binarySearchUntil(ac.content, target)
if result.exactMatch {
return int(result.value)
}
if result.outOfBounds() {
return -1
}

if result.index < len(ac.content)-1 {
return int(ac.content[result.index+1])
Expand Down
1 change: 1 addition & 0 deletions roaringarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type container interface {
nextValue(x uint16) int
previousValue(x uint16) int
nextAbsentValue(x uint16) int
previousAbsentValue(x uint16) int
}

type contype uint8
Expand Down
1 change: 0 additions & 1 deletion runcontainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2337,7 +2337,6 @@ func TestNextPreviousValue(t *testing.T) {
assert.Equal(t, 39, runContainer.previousValue(45))
assert.Equal(t, -1, runContainer.previousValue(80))

assert.Equal(t, 45, runContainer.nextAbsentValue(45))
assert.Equal(t, -1, runContainer.nextAbsentValue(0))
assert.Equal(t, -1, runContainer.nextAbsentValue(1))
assert.Equal(t, 10, runContainer.nextAbsentValue(5))
Expand Down

0 comments on commit 8828ae8

Please sign in to comment.