11 #ifndef EMP_BITSET_UTILS_H 12 #define EMP_BITSET_UTILS_H 19 template <
int NUM_BITS>
20 constexpr uint32_t
UIntMaskFirst() {
return (UIntMaskFirst<NUM_BITS-1> << 1) | 1; }
28 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
29 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
30 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
31 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
32 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
33 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
34 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
35 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
41 ByteCount[ val >> 56 ] +
42 ByteCount[ (val >> 48) & 0xFF ] +
43 ByteCount[ (val >> 40) & 0xFF ] +
44 ByteCount[ (val >> 32) & 0xFF ] +
45 ByteCount[ (val >> 24) & 0xFF ] +
46 ByteCount[ (val >> 16) & 0xFF ] +
47 ByteCount[ (val >> 8) & 0xFF ] +
48 ByteCount[ val & 0xFF ];
54 ByteCount[ val >> 24 ] +
55 ByteCount[ (val >> 16) & 0xFF ] +
56 ByteCount[ (val >> 8) & 0xFF ] +
57 ByteCount[ val & 0xFF ];
61 inline constexpr
size_t find_bit(
const uint64_t & val) {
return count_bits( (~val) & (val-1) ); }
64 inline constexpr
size_t find_bit(
const uint32_t & val) {
return count_bits( (~val) & (val-1) ); }
constexpr size_t ByteCount[256]
How many bits are set to one in each possible byte?
Definition: bitset_utils.h:27
constexpr size_t count_bits(uint64_t val)
Count the number of bits in a 64-bit unsigned integer.
Definition: bitset_utils.h:39
constexpr uint32_t UIntMaskFirst()
Create a series of a specified number of ones (at compile time) in a uint.
Definition: bitset_utils.h:20
If we are in emscripten, make sure to include the header.
Definition: array.h:37
constexpr size_t find_bit(const uint64_t &val)
Return the position of the first one bit (in a 64-bit unsigned int)
Definition: bitset_utils.h:61
constexpr uint32_t UIntMaskFirst< 0 >()
Create an empty bit mask (all zeros)
Definition: bitset_utils.h:24