Skip to content

Commit

Permalink
Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Aug 17, 2018
1 parent 2d4e848 commit 4ec4abb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (b *BitSet) NextSetMany(i uint, buffer []uint) (uint, []uint) {
return 0, myanswer
}
w := b.set[x]
skip := i & (wordSize - 1)
skip := i & (wordSize - 1)
w = (w >> skip) << skip
base := uint(x << 6)
capacity := cap(buffer)
Expand Down
31 changes: 29 additions & 2 deletions bitset_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func BenchmarkFlorianUekermannIterateMany(b *testing.B) {
setRnd(input, 4)
var bitmap = From(input)
b.ResetTimer()
var checksum = uint(0)
var checksum = uint(0)
for i := 0; i < b.N; i++ {
buffer := make([]uint, 256)
var last, batch = bitmap.NextSetMany(0, buffer)
Expand All @@ -218,7 +218,7 @@ func BenchmarkFlorianUekermannIterateManyReg(b *testing.B) {
setRnd(input, 4)
var bitmap = From(input)
b.ResetTimer()
var checksum = uint(0)
var checksum = uint(0)
for i := 0; i < b.N; i++ {
for j, e := bitmap.NextSet(0); e; j, e = bitmap.NextSet(j + 1) {
checksum += j
Expand All @@ -228,3 +228,30 @@ func BenchmarkFlorianUekermannIterateManyReg(b *testing.B) {
return
}
}

func good(set []uint64) (checksum uint) {
for wordIdx, word := range set {
var wordIdx = uint(wordIdx * 64)
for word != 0 {
var bitIdx = uint(trailingZeroes64(word))
word ^= 1 << bitIdx
// Do something with the result of the next line
var index = wordIdx + bitIdx
checksum += index
}
}
return checksum
}

func BenchmarkFlorianUekermannIterateManyComp(b *testing.B) {
var input = make([]uint64, 68)
setRnd(input, 4)
b.ResetTimer()
var checksum = uint(0)
for i := 0; i < b.N; i++ {
checksum += good(input)
}
if checksum == 0 { // added just to fool ineffassign
return
}
}

0 comments on commit 4ec4abb

Please sign in to comment.