27 static inline uint64_t divide_longs_rounding_up(uint64_t x, uint64_t y) {
28 if (y == 0)
throw std::invalid_argument(
"divide_longs_rounding_up: bad argument");
29 const uint64_t quotient = x / y;
30 if (quotient * y == x)
return (quotient);
31 else return quotient + 1;
34 static inline uint8_t floor_log2_of_long(uint64_t x) {
35 if (x < 1)
throw std::invalid_argument(
"floor_log2_of_long: bad argument");
40 if (y > x)
return p - 1;
50 static inline uint64_t wegner_count_bits_set_in_matrix(
const uint64_t* array,
size_t length) {
56 for (uint64_t i = 0; i < length; i++) {
58 while (pattern != 0) {
59 pattern &= (pattern - 1);
72 static inline uint32_t warren_bit_count(uint64_t i) {
73 i = i - ((i >> 1) & 0x5555555555555555ULL);
74 i = (i & 0x3333333333333333ULL) + ((i >> 2) & 0x3333333333333333ULL);
75 i = (i + (i >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
82 static inline uint32_t warren_count_bits_set_in_matrix(
const uint64_t* array, uint32_t length) {
84 for (uint32_t i = 0; i < length; i++) {
85 count += warren_bit_count(array[i]);
92 #define DATASKETCHES_CSA(h, l, a, b, c) \
96 h = (a & b) | (u & v); \
100 static inline uint32_t count_bits_set_in_matrix(
const uint64_t* a, uint32_t length) {
101 if ((length & 0x7) != 0)
throw std::invalid_argument(
"the length of the array must be a multiple of 8");
103 uint64_t ones, twos, twos_a, twos_b, fours, fours_a, fours_b, eights;
104 fours = twos = ones = 0;
106 for (uint32_t i = 0; i <= length - 8; i += 8) {
107 DATASKETCHES_CSA(twos_a, ones, ones, a[i+0], a[i+1]);
108 DATASKETCHES_CSA(twos_b, ones, ones, a[i+2], a[i+3]);
109 DATASKETCHES_CSA(fours_a, twos, twos, twos_a, twos_b);
111 DATASKETCHES_CSA(twos_a, ones, ones, a[i+4], a[i+5]);
112 DATASKETCHES_CSA(twos_b, ones, ones, a[i+6], a[i+7]);
113 DATASKETCHES_CSA(fours_b, twos, twos, twos_a, twos_b);
115 DATASKETCHES_CSA(eights, fours, fours, fours_a, fours_b);
117 total += warren_bit_count(eights);
119 total = 8 * total + 4 * warren_bit_count(fours) + 2 * warren_bit_count(twos) + warren_bit_count(ones);
128 #undef DATASKETCHES_CSA
DataSketches namespace.
Definition: binomial_bounds.hpp:38