Skip to content

Commit

Permalink
Minor fix to Shrink.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Sep 9, 2021
1 parent 59de210 commit 5a82924
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ func (b *BitSet) Shrink(lastbitindex uint) *BitSet {
copy(shrunk, b.set[:idx])
b.set = shrunk
b.length = length
b.set[idx-1] &= (allBits >> (uint64(64) - uint64(length&(wordSize-1))))
if length < 64 {
b.set[idx-1] &= (allBits >> (uint64(64) - uint64(length&(wordSize-1))))
}
return b
}

Expand Down
7 changes: 7 additions & 0 deletions bitset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,13 @@ func TestAll(t *testing.T) {
}

func TestShrink(t *testing.T) {
bs := New(10)
bs.Set(0)
bs.Shrink(63)
if !bs.Test(0) {
t.Error("0 should be set")
return
}
b := New(0)

b.Set(0)
Expand Down

0 comments on commit 5a82924

Please sign in to comment.