Skip to content

Commit

Permalink
Merge pull request #101 from bits-and-blooms/dlemire/issue92
Browse files Browse the repository at this point in the history
Verifying and checking issue 100.
  • Loading branch information
lemire authored Mar 18, 2022
2 parents 04f5e3f + a1cbd25 commit c263434
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 @@ -231,7 +231,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 c263434

Please sign in to comment.