BitMask
State Variables
M1
Constants used to efficiently calculate the hamming weight of a bitfield. See https://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation for an explanation of those constants.
uint256 internal constant M1 = 0x5555555555555555555555555555555555555555555555555555555555555555;
M2
uint256 internal constant M2 = 0x3333333333333333333333333333333333333333333333333333333333333333;
M4
uint256 internal constant M4 = 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f;
M8
uint256 internal constant M8 = 0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff;
M16
uint256 internal constant M16 = 0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff;
M32
uint256 internal constant M32 = 0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff;
M64
uint256 internal constant M64 = 0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff;
M128
uint256 internal constant M128 = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;
BITS_IN_LIMB
uint256 internal constant BITS_IN_LIMB = 256;
NNNN
uint256 internal constant NNNN = 4;
Functions
count_ones
Calculates the number of set bits by using the hamming weight of the bitfield. The algorithm below is implemented after https://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation. Further improvements are possible, see the article above.
function count_ones(Bitmask memory self) internal pure returns (uint256);
Parameters
| Name | Type | Description | 
|---|---|---|
| self | Bitmask | Bitmask. | 
Returns
| Name | Type | Description | 
|---|---|---|
| <none> | uint256 | Ones count of bitmask. | 
count_ones
function count_ones(uint256 x) internal pure returns (uint256);
size
Actual size of bitmask, not including the padding.
function size(Bitmask memory self) internal pure returns (uint256);
Parameters
| Name | Type | Description | 
|---|---|---|
| self | Bitmask | Bitmask. | 
Returns
| Name | Type | Description | 
|---|---|---|
| <none> | uint256 | Size of bitmask. | 
at
Bit at index of bitmask.
function at(Bitmask memory self, uint256 index) internal pure returns (bool);
Parameters
| Name | Type | Description | 
|---|---|---|
| self | Bitmask | Bitmask. | 
| index | uint256 | The index of bitmask. | 
Returns
| Name | Type | Description | 
|---|---|---|
| <none> | bool | Bit at index of bitmask. | 
serialize
function serialize(Bitmask memory self) internal pure returns (bytes memory);