Skip to content

Commit

Permalink
Merge pull request #313 from Oppen/fix_bitset_addOffset
Browse files Browse the repository at this point in the history
OR the intermediate values in bitmapContainer.addOffset
  • Loading branch information
lemire authored Jun 8, 2021
2 parents 2feadb1 + 8fc1aec commit c57a7b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions bitmapcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,16 +1138,12 @@ func (bc *bitmapContainer) addOffset(x uint16) []container {
low.bitmap[b] = bc.bitmap[0] << i
for k := uint32(1); k < end; k++ {
newval := bc.bitmap[k] << i
if newval == 0 {
newval = bc.bitmap[k-1] >> (64 - i)
}
newval |= bc.bitmap[k-1] >> (64 - i)
low.bitmap[b+k] = newval
}
for k := end; k < 1024; k++ {
newval := bc.bitmap[k] << i
if newval == 0 {
newval = bc.bitmap[k-1] >> (64 - i)
}
newval |= bc.bitmap[k-1] >> (64 - i)
high.bitmap[k-end] = newval
}
high.bitmap[b] = bc.bitmap[1023] >> (64 - i)
Expand Down
4 changes: 2 additions & 2 deletions bitmapcontainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func BenchmarkShortIteratorNextBitmap(b *testing.B) {
}

func TestBitmapOffset(t *testing.T) {
nums := []uint16{10, 100, 1000}
nums := []uint16{10, 60, 70, 100, 1000}
expected := make([]int, len(nums))
offtest := uint16(65000)
v := container(newBitmapContainer())
Expand All @@ -225,7 +225,7 @@ func TestBitmapOffset(t *testing.T) {
w0card := w[0].getCardinality()
w1card := w[1].getCardinality()

assert.Equal(t, 3, w0card+w1card)
assert.Equal(t, v.getCardinality(), w0card+w1card)

wout := make([]int, len(nums))
for i := 0; i < w0card; i++ {
Expand Down

0 comments on commit c57a7b2

Please sign in to comment.