Documentation
¶
Index ¶
- func CeilPowOf2(target uint64) uint8
- func HammingWeightByGroupCount[T Number](n T) uint8
- func HammingWeightBySWARV1[T Number](n T) uint8
- func HammingWeightBySWARV2[T Number](n T) uint8
- func HammingWeightBySWARV3[T Number](n T) uint8
- func IsPowOf2(target uint64) bool
- func RoundupPowOf2(target uint64) uint64
- func RoundupPowOf2ByCeil(target uint64) uint64
- func RoundupPowOf2ByLoop(target uint64) uint64
- type BitCount
- type Bitmap
- type HammingWeight
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CeilPowOf2 ¶
CeilPowOf2 get the ceil power of 2 of the target. Copy from linux kernel kfifo.
func HammingWeightBySWARV1 ¶
HammingWeightBySWARV1 counts the number of 1 by group statistics. Calculate the number of 1 bit by tree-like structure. Example: 0x55555555 = 01010101010101010101010101010101 It will keep the odd bits of the original number 1 and keep the even bits of the original number 1. Every 2 binary bits represent the number of 1 in the corresponding binary bit of the original number. 0x33333333 = 00110011001100110011001100110011 It will keep the right two bits of the sum of the previous step and keep the left two bits of the sum of the previous step. Every 4 binary bits represent the number of 1 in the corresponding binary bit of the original number. 0x0f0f0f0f = 00001111000011110000111100001111 It will keep the right four bits of the sum of the previous step and keep the left four bits of the sum of the previous step. Every 8 binary bits represent the number of 1 in the corresponding binary bit of the original number. 0x00ff00ff = 00000000111111110000000011111111 It will keep the right eight bits of the sum of the previous step and keep the left eight bits of the sum of the previous step. Every 16 binary bits represent the number of 1 in the corresponding binary bit of the original number. 0x0000ffff = 00000000000000001111111111111111 It will keep the right sixteen bits of the sum of the previous step and keep the left sixteen bits of the sum of the previous step. Every 32 binary bits represent the number of 1 in the corresponding binary bit of the original number.
func HammingWeightBySWARV2 ¶
HammingWeightBySWARV2 counts the number of 1 by group statistics. Example: 7 = (0111)2 step 1: 0x7 & 0x55555555 = 0x5 0x7 >> 1 = 0x3, 0x3 & 0x55555555 = 0x1 0x5 + 0x1 = 0x6 step 2: 0x6 & 0x33333333 = 0x2 0x6 >> 2 = 0x1, 0x1 & 0x33333333 = 0x1 0x2 + 0x1 = 0x3 step 3: 0x3 & 0x0f0f0f0f = 0x3 0x3 >> 4 = 0x0, 0x0 & 0x0f0f0f0f = 0x0 0x3 + 0x0 = 0x3 step 4: 0x3 * 0x01010101 = 0x03030303 0x03030303 & 0x3fffffff = 0x03030303 0x03030303 >> 24 = 0x3
func HammingWeightBySWARV3 ¶
HammingWeightBySWARV3 counts the number of 1 by group statistics.
func RoundupPowOf2 ¶
func RoundupPowOf2ByCeil ¶
RoundupPowOf2ByCeil rounds up the target to the power of 2. Copy from linux kernel kfifo.
func RoundupPowOf2ByLoop ¶
RoundupPowOf2ByLoop rounds up the target to the power of 2. Plain thinking.
Types ¶
type BitCount ¶
type BitCount[T Number] HammingWeight[T]
type Bitmap ¶
type Bitmap interface { SetBit(offset uint64) bool UnsetBit(offset uint64) bool GetBit(offset uint64) bool GetBits() []byte EqualTo(bm Bitmap) bool Purge() }
func NewX32Bitmap ¶
type HammingWeight ¶
HammingWeight counts the number of 1 bit in a number.