20 "threshold to count bits with buckets");
26#define BIT_COUNT_RANGE(size, zero) \
27 uint##size##_t BitCountRange##size(const uint##size##_t* const bits, \
28 uint##size##_t start, \
29 uint##size##_t end) { \
30 if (static_cast<int##size##_t>(end - start) > \
31 absl::GetFlag(FLAGS_bitset_small_bitset_count)) { \
32 const int offset_start = BitOffset##size(start); \
33 const int pos_start = BitPos##size(start); \
34 const int offset_end = BitOffset##size(end); \
35 const int pos_end = BitPos##size(end); \
36 if (offset_end == offset_start) { \
37 return BitCount##size(bits[offset_start] & \
38 OneRange##size(pos_start, pos_end)); \
40 uint##size##_t bit_count = zero; \
42 BitCount##size(bits[offset_start] & IntervalUp##size(pos_start)); \
43 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \
44 bit_count += BitCount##size(bits[offset]); \
47 BitCount##size(bits[offset_end] & IntervalDown##size(pos_end)); \
51 uint##size##_t bit_count = zero; \
52 for (uint##size##_t i = start; i <= end; ++i) { \
53 bit_count += IsBitSet##size(bits, i); \
64#define IS_EMPTY_RANGE(size) \
65 bool IsEmptyRange##size(const uint##size##_t* const bits, \
66 uint##size##_t start, uint##size##_t end) { \
67 const int offset_start = BitOffset##size(start); \
68 const int pos_start = BitPos##size(start); \
69 const int offset_end = BitOffset##size(end); \
70 const int pos_end = BitPos##size(end); \
71 if (offset_end == offset_start) { \
72 if (bits[offset_start] & OneRange##size(pos_start, pos_end)) { \
76 if (bits[offset_start] & IntervalUp##size(pos_start)) { \
79 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \
84 if (bits[offset_end] & IntervalDown##size(pos_end)) { \
96#define LEAST_SIGNIFCANT_BIT_POSITION(size) \
97 int##size##_t LeastSignificantBitPosition##size( \
98 const uint##size##_t* const bits, uint##size##_t start, \
99 uint##size##_t end) { \
100 DCHECK_LE(start, end); \
101 if (IsBitSet##size(bits, start)) { \
104 const int offset_start = BitOffset##size(start); \
105 const int offset_end = BitOffset##size(end); \
106 const int pos_start = BitPos##size(start); \
107 if (offset_start == offset_end) { \
108 const int pos_end = BitPos##size(end); \
109 const uint##size##_t active_range = \
110 bits[offset_start] & OneRange##size(pos_start, pos_end); \
111 if (active_range) { \
112 return BitShift##size(offset_start) + \
113 LeastSignificantBitPosition##size(active_range); \
117 const uint##size##_t start_mask = \
118 bits[offset_start] & IntervalUp##size(pos_start); \
120 return BitShift##size(offset_start) + \
121 LeastSignificantBitPosition##size(start_mask); \
123 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \
124 if (bits[offset]) { \
125 return BitShift##size(offset) + \
126 LeastSignificantBitPosition##size(bits[offset]); \
129 const int pos_end = BitPos##size(end); \
130 const uint##size##_t active_range = \
131 bits[offset_end] & IntervalDown##size(pos_end); \
132 if (active_range) { \
133 return BitShift##size(offset_end) + \
134 LeastSignificantBitPosition##size(active_range); \
145#undef LEAST_SIGNIFCANT_BIT_POSITION
147#define MOST_SIGNIFICANT_BIT_POSITION(size) \
148 int##size##_t MostSignificantBitPosition##size( \
149 const uint##size##_t* const bits, uint##size##_t start, \
150 uint##size##_t end) { \
151 DCHECK_GE(end, start); \
152 if (IsBitSet##size(bits, end)) { \
155 const int offset_start = BitOffset##size(start); \
156 const int offset_end = BitOffset##size(end); \
157 const int pos_end = BitPos##size(end); \
158 if (offset_start == offset_end) { \
159 const int pos_start = BitPos##size(start); \
160 const uint##size##_t active_range = \
161 bits[offset_start] & OneRange##size(pos_start, pos_end); \
162 if (active_range) { \
163 return BitShift##size(offset_end) + \
164 MostSignificantBitPosition##size(active_range); \
169 const uint##size##_t end_mask = \
170 bits[offset_end] & IntervalDown##size(pos_end); \
172 return BitShift##size(offset_end) + \
173 MostSignificantBitPosition##size(end_mask); \
175 for (int offset = offset_end - 1; offset > offset_start; --offset) { \
176 if (bits[offset]) { \
177 return BitShift##size(offset) + \
178 MostSignificantBitPosition##size(bits[offset]); \
181 const int pos_start = BitPos##size(start); \
182 const uint##size##_t active_range = \
183 bits[offset_start] & IntervalUp##size(pos_start); \
184 if (active_range) { \
185 return BitShift##size(offset_start) + \
186 MostSignificantBitPosition##size(active_range); \
197#undef MOST_SIGNIFICANT_BIT_POSITION
199#define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size) \
200 int##size##_t UnsafeLeastSignificantBitPosition##size( \
201 const uint##size##_t* const bits, uint##size##_t start, \
202 uint##size##_t end) { \
203 DCHECK_LE(start, end); \
204 DCHECK(IsBitSet##size(bits, end)); \
205 if (IsBitSet##size(bits, start)) { \
208 const int offset_start = BitOffset##size(start); \
209 const int offset_end = BitOffset##size(end); \
210 const int pos_start = BitPos##size(start); \
211 const uint##size##_t start_mask = \
212 bits[offset_start] & IntervalUp##size(pos_start); \
214 return BitShift##size(offset_start) + \
215 LeastSignificantBitPosition##size(start_mask); \
217 for (int offset = offset_start + 1; offset <= offset_end; ++offset) { \
218 if (bits[offset]) { \
219 return BitShift##size(offset) + \
220 LeastSignificantBitPosition##size(bits[offset]); \
229#undef UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION
231#define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size) \
232 int##size##_t UnsafeMostSignificantBitPosition##size( \
233 const uint##size##_t* const bits, uint##size##_t start, \
234 uint##size##_t end) { \
235 DCHECK_GE(end, start); \
236 DCHECK(IsBitSet##size(bits, start)); \
237 if (IsBitSet##size(bits, end)) { \
240 const int offset_start = BitOffset##size(start); \
241 const int offset_end = BitOffset##size(end); \
242 const int pos_end = BitPos##size(end); \
243 const uint##size##_t end_mask = \
244 bits[offset_end] & IntervalDown##size(pos_end); \
246 return BitShift##size(offset_end) + \
247 MostSignificantBitPosition##size(end_mask); \
249 for (int offset = offset_end - 1; offset >= offset_start; --offset) { \
250 if (bits[offset]) { \
251 return BitShift##size(offset) + \
252 MostSignificantBitPosition##size(bits[offset]); \
261#undef UNSAFE_MOST_SIGNIFICANT_BIT_POSITION
#define LEAST_SIGNIFCANT_BIT_POSITION(size)
#define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size)
#define MOST_SIGNIFICANT_BIT_POSITION(size)
#define IS_EMPTY_RANGE(size)
#define BIT_COUNT_RANGE(size, zero)
-------— Bit Operations -------—
ABSL_FLAG(int, bitset_small_bitset_count, 8, "threshold to count bits with buckets")
#define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size)
In SWIG mode, we don't want anything besides these top-level includes.