Skip to content

Commit

Permalink
Verifying and checking issue 92.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Mar 4, 2022
1 parent dfa3e34 commit a1cbd25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ func (b *BitSet) FlipRange(start, end uint) *BitSet {
for i := startWord; i < endWord; i++ {
b.set[i] = ^b.set[i]
}
b.set[endWord] ^= ^uint64(0) >> (-end & (wordSize - 1))
if end & (wordSize - 1) != 0 {
b.set[endWord] ^= ^uint64(0) >> (-end & (wordSize - 1))
}
return b
}

Expand Down
12 changes: 12 additions & 0 deletions bitset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,18 @@ func TestFlipRange(t *testing.T) {
t.Error("Unexpected value: ", d.length)
return
}
//
for i := uint(0); i < 256; i++ {
for j := uint(0); j <= i; j++ {
bits := New(i)
bits.FlipRange(0, j)
c := bits.Count()
if c != j {
t.Error("Unexpected value: ", c, " expected: ", j)
return
}
}
}
}

func TestCopy(t *testing.T) {
Expand Down

0 comments on commit a1cbd25

Please sign in to comment.