@@ -51,7 +51,7 @@ func (bc *bitmapContainer) minimum() uint16 {
5151 for i := 0 ; i < len (bc .bitmap ); i ++ {
5252 w := bc .bitmap [i ]
5353 if w != 0 {
54- r := countTrailingZeros (w )
54+ r := bits . TrailingZeros64 (w )
5555 return uint16 (r + i * 64 )
5656 }
5757 }
@@ -73,7 +73,7 @@ func (bc *bitmapContainer) maximum() uint16 {
7373 for i := len (bc .bitmap ); i > 0 ; i -- {
7474 w := bc .bitmap [i - 1 ]
7575 if w != 0 {
76- return uint16 ((i - 1 )* 64 + 63 - countLeadingZeros (w ))
76+ return uint16 ((i - 1 )* 64 + 63 - bits . LeadingZeros64 (w ))
7777 }
7878 }
7979 return uint16 (0 )
@@ -188,7 +188,7 @@ func (bcmi *bitmapContainerManyIterator) nextMany(hs uint32, buf []uint32) int {
188188 continue
189189 }
190190 t := bitset & - bitset
191- buf [n ] = uint32 (((base * 64 ) + int ( popcount ( t - 1 ) ))) | hs
191+ buf [n ] = uint32 (((base * 64 ) + bits . OnesCount64 ( t - 1 ))) | hs
192192 n = n + 1
193193 bitset ^= t
194194 }
@@ -216,7 +216,7 @@ func (bcmi *bitmapContainerManyIterator) nextMany64(hs uint64, buf []uint64) int
216216 continue
217217 }
218218 t := bitset & - bitset
219- buf [n ] = uint64 (((base * 64 ) + int ( popcount ( t - 1 ) ))) | hs
219+ buf [n ] = uint64 (((base * 64 ) + bits . OnesCount64 ( t - 1 ))) | hs
220220 n = n + 1
221221 bitset ^= t
222222 }
@@ -302,7 +302,7 @@ func (bc *bitmapContainer) fillLeastSignificant16bits(x []uint32, i int, mask ui
302302 bitset := bc .bitmap [k ]
303303 for bitset != 0 {
304304 t := bitset & - bitset
305- x [pos ] = base + uint32 (popcount (t - 1 ))
305+ x [pos ] = base + uint32 (bits . OnesCount64 (t - 1 ))
306306 pos ++
307307 bitset ^= t
308308 }
@@ -698,13 +698,13 @@ func (bc *bitmapContainer) rank(x uint16) int {
698698 if leftover == 0 {
699699 return int (popcntSlice (bc .bitmap [:(uint (x )+ 1 )/ 64 ]))
700700 }
701- return int (popcntSlice (bc .bitmap [:(uint (x )+ 1 )/ 64 ]) + popcount (bc .bitmap [(uint (x )+ 1 )/ 64 ]<< (64 - leftover ) ))
701+ return int (popcntSlice (bc .bitmap [:(uint (x )+ 1 )/ 64 ])) + bits . OnesCount64 (bc .bitmap [(uint (x )+ 1 )/ 64 ]<< (64 - leftover ))
702702}
703703
704704func (bc * bitmapContainer ) selectInt (x uint16 ) int {
705705 remaining := x
706706 for k := 0 ; k < len (bc .bitmap ); k ++ {
707- w := popcount (bc .bitmap [k ])
707+ w := bits . OnesCount64 (bc .bitmap [k ])
708708 if uint16 (w ) > remaining {
709709 return k * 64 + selectBitPosition (bc .bitmap [k ], int (remaining ))
710710 }
@@ -830,11 +830,11 @@ func (bc *bitmapContainer) getCardinalityInRange(start, end uint) int {
830830 endword := (end - 1 ) / 64
831831 const allones = ^ uint64 (0 )
832832 if firstword == endword {
833- return int ( popcount ( bc .bitmap [firstword ] & ((allones << (start % 64 )) & (allones >> ((64 - end ) & 63 ) ))))
833+ return bits . OnesCount64 ( bc .bitmap [firstword ] & ((allones << (start % 64 )) & (allones >> ((64 - end ) & 63 ))))
834834 }
835- answer := popcount ( bc .bitmap [firstword ] & (allones << (start % 64 )))
835+ answer := uint64 ( bits . OnesCount64 ( bc .bitmap [firstword ] & (allones << (start % 64 ) )))
836836 answer += popcntSlice (bc .bitmap [firstword + 1 : endword ])
837- answer += popcount ( bc .bitmap [endword ] & (allones >> ((64 - end ) & 63 )))
837+ answer += uint64 ( bits . OnesCount64 ( bc .bitmap [endword ] & (allones >> ((64 - end ) & 63 ) )))
838838 return int (answer )
839839}
840840
@@ -972,7 +972,7 @@ func (bc *bitmapContainer) iandNotArray(ac *arrayContainer) container {
972972 // are set in the mask and in the current word.
973973 mask &= bc .bitmap [wordIdx ]
974974 bc .bitmap [wordIdx ] &= ^ mask
975- bc .cardinality -= int ( popcount ( mask ) )
975+ bc .cardinality -= bits . OnesCount64 ( mask )
976976 }
977977
978978 wordIdx = v / 64
@@ -984,7 +984,7 @@ func (bc *bitmapContainer) iandNotArray(ac *arrayContainer) container {
984984 // Flush the last word.
985985 mask &= bc .bitmap [wordIdx ]
986986 bc .bitmap [wordIdx ] &= ^ mask
987- bc .cardinality -= int ( popcount ( mask ) )
987+ bc .cardinality -= bits . OnesCount64 ( mask )
988988
989989 if bc .getCardinality () <= arrayDefaultMaxSize {
990990 return bc .toArrayContainer ()
@@ -1124,7 +1124,7 @@ func (bc *bitmapContainer) fillArray(container []uint16) {
11241124 bitset := bc .bitmap [k ]
11251125 for bitset != 0 {
11261126 t := bitset & - bitset
1127- container [pos ] = uint16 ((base + int ( popcount ( t - 1 ) )))
1127+ container [pos ] = uint16 ((base + bits . OnesCount64 ( t - 1 )))
11281128 pos = pos + 1
11291129 bitset ^= t
11301130 }
@@ -1144,12 +1144,12 @@ func (bc *bitmapContainer) NextSetBit(i uint) int {
11441144 w := bc .bitmap [x ]
11451145 w = w >> (i % 64 )
11461146 if w != 0 {
1147- return int (i ) + countTrailingZeros (w )
1147+ return int (i ) + bits . TrailingZeros64 (w )
11481148 }
11491149 x ++
11501150 for ; x < length ; x ++ {
11511151 if bc .bitmap [x ] != 0 {
1152- return int (x * 64 ) + countTrailingZeros (bc .bitmap [x ])
1152+ return int (x * 64 ) + bits . TrailingZeros64 (bc .bitmap [x ])
11531153 }
11541154 }
11551155 return - 1
@@ -1167,12 +1167,12 @@ func (bc *bitmapContainer) NextUnsetBit(i uint) int {
11671167 w = w >> (i % 64 )
11681168 w = ^ w
11691169 if w != 0 {
1170- return int (i ) + countTrailingZeros (w )
1170+ return int (i ) + bits . TrailingZeros64 (w )
11711171 }
11721172 x ++
11731173 for ; x < length ; x ++ {
11741174 if bc .bitmap [x ] != 0xFFFFFFFFFFFFFFFF {
1175- return int (x * 64 ) + countTrailingZeros (^ bc .bitmap [x ])
1175+ return int (x * 64 ) + bits . TrailingZeros64 (^ bc .bitmap [x ])
11761176 }
11771177 }
11781178 return int (length * 64 )
@@ -1203,7 +1203,7 @@ func (bc *bitmapContainer) uPrevSetBit(i uint) int {
12031203
12041204 w = w << (63 - b )
12051205 if w != 0 {
1206- return int (i ) - countLeadingZeros (w )
1206+ return int (i ) - bits . LeadingZeros64 (w )
12071207 }
12081208 orig := x
12091209 x --
@@ -1212,7 +1212,7 @@ func (bc *bitmapContainer) uPrevSetBit(i uint) int {
12121212 }
12131213 for ; x < orig ; x -- {
12141214 if bc .bitmap [x ] != 0 {
1215- return int ((x * 64 )+ 63 ) - countLeadingZeros (bc .bitmap [x ])
1215+ return int ((x * 64 )+ 63 ) - bits . LeadingZeros64 (bc .bitmap [x ])
12161216 }
12171217 }
12181218 return - 1
@@ -1231,11 +1231,11 @@ func (bc *bitmapContainer) numberOfRuns() int {
12311231 for i := 0 ; i < len (bc .bitmap )- 1 ; i ++ {
12321232 word := nextWord
12331233 nextWord = bc .bitmap [i + 1 ]
1234- numRuns += popcount (( ^ word )& (word << 1 )) + ((word >> 63 ) &^ nextWord )
1234+ numRuns += uint64 ( bits . OnesCount64 (( ^ word )& (word << 1 ) )) + ((word >> 63 ) &^ nextWord )
12351235 }
12361236
12371237 word := nextWord
1238- numRuns += popcount (( ^ word ) & (word << 1 ))
1238+ numRuns += uint64 ( bits . OnesCount64 (( ^ word ) & (word << 1 ) ))
12391239 if (word & 0x8000000000000000 ) != 0 {
12401240 numRuns ++
12411241 }
@@ -1379,14 +1379,14 @@ func (bc *bitmapContainer) nextAbsentValue(target uint16) int {
13791379 // if statement - we skip the if we have all ones [1,1,1,1...1]
13801380 if ^ w != 0 {
13811381
1382- if countTrailingZeros (w ) > 0 {
1382+ if bits . TrailingZeros64 (w ) > 0 {
13831383 // we have something like [X,Y,Z, 0,0,0]. This means the target bit is zero
13841384 return int (target )
13851385 }
13861386
13871387 // other wise something like [X,Y,0,1,1,1..1], where x and y can be either 1 or 0.
13881388
1389- trailing := countTrailingOnes ( w )
1389+ trailing := bits . TrailingZeros64 ( ^ w )
13901390 return int (target ) + trailing
13911391
13921392 }
@@ -1396,7 +1396,7 @@ func (bc *bitmapContainer) nextAbsentValue(target uint16) int {
13961396 return int (x * 64 )
13971397 }
13981398 if ^ bc .bitmap [x ] != 0 {
1399- trailing := countTrailingOnes ( bc .bitmap [x ])
1399+ trailing := bits . TrailingZeros64 ( ^ bc .bitmap [x ])
14001400 return int (x * 64 ) + trailing
14011401 }
14021402
@@ -1446,25 +1446,25 @@ func (bc *bitmapContainer) previousAbsentValue(target uint16) int {
14461446 // if statement - we skip if we have all ones [1,1,1,1...1] as no value is absent
14471447 if ^ shifted != 0 {
14481448
1449- if countTrailingZeros (shifted ) > 0 {
1449+ if bits . TrailingZeros64 (shifted ) > 0 {
14501450 // we have something like shifted=[X,Y,Z,..., 0,0,0]. This means the target bit is zero
14511451 return int (target )
14521452 }
14531453
14541454 // The rotate will rotate the target bit into the leading position.
1455- // We know the target bit is not zero because of the countTrailingZero check above
1455+ // We know the target bit is not zero because of the TrailingZeros64 check above
14561456 // We then shift the target bit out of the way.
14571457 // Assume a structure like an original structure like [X,Y,Z,..., Target, A, B,C...]
14581458 // shifted will be [X,Y,Z...Target]
14591459 // shiftedRotated will be [A,B,C....]
1460- // If countLeadingZeros > 0 then A is zero, if not at least A is 1 return
1460+ // If LeadingZeros64 > 0 then A is zero, if not at least A is 1 return
14611461 // Else count the number of ones's until a 0
14621462 shiftedRotated := bits .RotateLeft64 (w , int (64 - uint (target % 64 ))- 1 ) << 1
1463- leadingZeros := countLeadingZeros (shiftedRotated )
1463+ leadingZeros := bits . LeadingZeros64 (shiftedRotated )
14641464 if leadingZeros > 0 {
14651465 return int (target ) - 1
14661466 }
1467- leadingOnes := countLeadingOnes ( shiftedRotated )
1467+ leadingOnes := bits . LeadingZeros64 ( ^ shiftedRotated )
14681468 if leadingOnes > 0 {
14691469 return int (target ) - leadingOnes - 1
14701470 }
@@ -1476,7 +1476,7 @@ func (bc *bitmapContainer) previousAbsentValue(target uint16) int {
14761476 return int (x * 64 )
14771477 }
14781478 if ^ bc .bitmap [x ] != 0 {
1479- trailing := countTrailingOnes ( bc .bitmap [x ])
1479+ trailing := bits . TrailingZeros64 ( ^ bc .bitmap [x ])
14801480 return int (x * 64 ) + trailing
14811481 }
14821482
0 commit comments