Skip to content

Commit

Permalink
bad merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Dec 9, 2024
1 parent 2108e73 commit a512614
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions bitset.go
Original file line number Diff line number Diff line change
Expand Up @@ -1462,15 +1462,15 @@ func (b *BitSet) OnesBetween(from, to uint) uint {
if startWord == endWord {
// Create mask for bits between from and to
mask := uint64((1<<endOffset)-1) &^ ((1 << startOffset) - 1)
return uint(popcount(b.set[startWord] & mask))
return uint(bits.OnesCount64(b.set[startWord] & mask))
}

var count uint

// Case 2: Bits span multiple words
// 2a: Count bits in first word (from startOffset to end of word)
startMask := ^uint64((1 << startOffset) - 1) // Mask for bits >= startOffset
count = uint(popcount(b.set[startWord] & startMask))
count = uint(bits.OnesCount64(b.set[startWord] & startMask))

// 2b: Count all bits in complete words between start and end
if endWord > startWord+1 {
Expand All @@ -1480,7 +1480,7 @@ func (b *BitSet) OnesBetween(from, to uint) uint {
// 2c: Count bits in last word (from start of word to endOffset)
if endOffset > 0 {
endMask := uint64(1<<endOffset) - 1 // Mask for bits < endOffset
count += uint(popcount(b.set[endWord] & endMask))
count += uint(bits.OnesCount64(b.set[endWord] & endMask))
}

return count
Expand Down Expand Up @@ -1530,7 +1530,7 @@ func (b *BitSet) ExtractTo(mask *BitSet, dst *BitSet) {

// Extract and compact bits according to mask
extracted := pext(b.set[i], mask.set[i])
bitsExtracted := uint(popcount(mask.set[i]))
bitsExtracted := uint(bits.OnesCount64(mask.set[i]))

// Calculate destination position
wordIdx := outPos >> log2WordSize
Expand Down Expand Up @@ -1600,7 +1600,7 @@ func (b *BitSet) DepositTo(mask *BitSet, dst *BitSet) {

// Deposit bits according to mask
dst.set[i] = (dst.set[i] &^ mask.set[i]) | pdep(sourceBits, mask.set[i])
inPos += uint(popcount(mask.set[i]))
inPos += uint(bits.OnesCount64(mask.set[i]))
}
}

Expand Down
9 changes: 5 additions & 4 deletions bitset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"io"
"math"
"math/bits"
"math/rand"
"strconv"
"testing"
Expand Down Expand Up @@ -2390,15 +2391,15 @@ func TestPext(t *testing.T) {
w := rng.Uint64()
m := rng.Uint64()
result := pext(w, m)
popCount := popcount(m)
popCount := bits.OnesCount64(m)

// Test invariants
if popCount > 0 && result >= (uint64(1)<<popCount) {
t.Fatalf("Case %d: result %x exceeds maximum possible value for mask with popcount %d",
i, result, popCount)
}

if popcount(result) > popcount(w&m) {
if bits.OnesCount64(result) > bits.OnesCount64(w&m) {
t.Fatalf("Case %d: result has more 1s than masked input: result=%x, input&mask=%x",
i, result, w&m)
}
Expand Down Expand Up @@ -2435,15 +2436,15 @@ func TestPdep(t *testing.T) {
w := rng.Uint64() // value to deposit
m := rng.Uint64() // mask
result := pdep(w, m)
popCount := popcount(m)
popCount := bits.OnesCount64(m)

// Test invariants
if result&^m != 0 {
t.Fatalf("Case %d: result %x has bits set outside of mask %x",
i, result, m)
}

if popcount(result) > popcount(w) {
if bits.OnesCount64(result) > bits.OnesCount64(w) {
t.Fatalf("Case %d: result has more 1s than input: result=%x, input=%x",
i, result, w)
}
Expand Down

2 comments on commit a512614

@tsenart
Copy link
Contributor

@tsenart tsenart commented on a512614 Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lemire: I'm getting this build error locally with 1.19.0. With Go modules we can't replace tags unfortunately, so we need a new tag v1.19.1.

# github.com/bits-and-blooms/bitset
/Users/tomas/go/pkg/mod/github.com/bits-and-blooms/[email protected]/bitset.go:1465:15: undefined: popcount
/Users/tomas/go/pkg/mod/github.com/bits-and-blooms/[email protected]/bitset.go:1473:15: undefined: popcount
/Users/tomas/go/pkg/mod/github.com/bits-and-blooms/[email protected]/bitset.go:1483:17: undefined: popcount
/Users/tomas/go/pkg/mod/github.com/bits-and-blooms/[email protected]/bitset.go:1533:25: undefined: popcount
/Users/tomas/go/pkg/mod/github.com/bits-and-blooms/[email protected]/bitset.go:1603:17: undefined: popcount

@lemire
Copy link
Member Author

@lemire lemire commented on a512614 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsenart Please pick up 1.19.1

Thanks for the report.

Please sign in to comment.