@@ -8,36 +8,20 @@ import (
8
8
// indexForBitPos returns the index within the collapsed array corresponding to
9
9
// the given bit in the bitset. The collapsed array contains only one entry
10
10
// per bit set in the bitfield, and this function is used to map the indices.
11
- func (n * Node ) indexForBitPosOld (bp int ) int {
12
- // TODO: an optimization could reuse the same 'mask' here and change the size
13
- // as needed. This isnt yet done as the bitset package doesnt make it easy
14
- // to do.
15
-
16
- // make a bitmask (all bits set) 'bp' bits long
17
- mask := new (big.Int ).Sub (new (big.Int ).Exp (big .NewInt (2 ), big .NewInt (int64 (bp )), nil ), big .NewInt (1 ))
18
- mask .And (mask , n .Bitfield )
19
-
20
- return popCount (mask )
21
- }
22
-
23
- func popCount (i * big.Int ) int {
24
- var n int
25
- for _ , v := range i .Bits () {
26
- n += bits .OnesCount64 (uint64 (v ))
27
- }
28
- return n
11
+ func (n * Node ) indexForBitPos (bp int ) int {
12
+ return indexForBitPos (bp , n .Bitfield )
29
13
}
30
14
31
- func ( n * Node ) indexForBitPos (bp int ) int {
15
+ func indexForBitPos (bp int , bitfield * big. Int ) int {
32
16
var x uint
33
17
var count , i int
34
- w := n . Bitfield .Bits ()
18
+ w := bitfield .Bits ()
35
19
for x = uint (bp ); x > bits .UintSize && i < len (w ); x -= bits .UintSize {
36
- count += bits .OnesCount64 ( uint64 (w [i ]))
20
+ count += bits .OnesCount ( uint (w [i ]))
37
21
i ++
38
22
}
39
23
if i == len (w ) {
40
24
return count
41
25
}
42
- return count + bits .OnesCount64 ( uint64 (w [i ])& ((1 << x )- 1 ))
26
+ return count + bits .OnesCount ( uint (w [i ])& ((1 << x )- 1 ))
43
27
}
0 commit comments