Fix bitArray's arch dependent serialization format
bitArray's serialization format was word size dependent. Since over 32
bits bitArray has not been used, it made no problem.
@@ -6,9 +6,9 @@ import (
"math/rand"
)
-type word = uint
+type word = uint64
-const wordBits = 32 << (^uint(0) >> 63) // either 32 or 64
+const wordBits = 64
type bitArray struct {
NumBits int
@@ -77,14 +77,14 @@ func (ba *bitArray) AssignAnd(ba2 *bitArray) {
func (ba *bitArray) PickRandom() int {
var count int
for i := 0; i < len(ba.Words); i++ {
- count = count + bits.OnesCount(ba.Words[i])
+ count = count + bits.OnesCount64(ba.Words[i])
}
if count == 0 {
return -1
}
pick := rand.Intn(count)
for i := 0; i < len(ba.Words); i++ {
- c := bits.OnesCount(ba.Words[i])
+ c := bits.OnesCount64(ba.Words[i])
if pick < c {
for idx := i * wordBits; idx < ba.NumBits; idx++ {
if ba.Get(idx) {
