 |
OR-Tools
8.1
|
Go to the documentation of this file.
20 "threshold to count bits with buckets");
26 #define BIT_COUNT_RANGE(size, zero) \
27 uint##size BitCountRange##size(const uint##size* const bits, \
28 uint##size start, uint##size end) { \
29 if (end - start > absl::GetFlag(FLAGS_bitset_small_bitset_count)) { \
30 const int offset_start = BitOffset##size(start); \
31 const int pos_start = BitPos##size(start); \
32 const int offset_end = BitOffset##size(end); \
33 const int pos_end = BitPos##size(end); \
34 if (offset_end == offset_start) { \
35 return BitCount##size(bits[offset_start] & \
36 OneRange##size(pos_start, pos_end)); \
38 uint##size bit_count = zero; \
40 BitCount##size(bits[offset_start] & IntervalUp##size(pos_start)); \
41 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \
42 bit_count += BitCount##size(bits[offset]); \
45 BitCount##size(bits[offset_end] & IntervalDown##size(pos_end)); \
49 uint##size bit_count = zero; \
50 for (uint##size i = start; i <= end; ++i) { \
51 bit_count += IsBitSet##size(bits, i); \
60 #undef BIT_COUNT_RANGE
62 #define IS_EMPTY_RANGE(size) \
63 bool IsEmptyRange##size(const uint##size* const bits, uint##size start, \
65 const int offset_start = BitOffset##size(start); \
66 const int pos_start = BitPos##size(start); \
67 const int offset_end = BitOffset##size(end); \
68 const int pos_end = BitPos##size(end); \
69 if (offset_end == offset_start) { \
70 if (bits[offset_start] & OneRange##size(pos_start, pos_end)) { \
74 if (bits[offset_start] & IntervalUp##size(pos_start)) { \
77 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \
82 if (bits[offset_end] & IntervalDown##size(pos_end)) { \
94 #define LEAST_SIGNIFCANT_BIT_POSITION(size) \
95 int##size LeastSignificantBitPosition##size( \
96 const uint##size* const bits, uint##size start, uint##size end) { \
97 DCHECK_LE(start, end); \
98 if (IsBitSet##size(bits, start)) { \
101 const int offset_start = BitOffset##size(start); \
102 const int offset_end = BitOffset##size(end); \
103 const int pos_start = BitPos##size(start); \
104 if (offset_start == offset_end) { \
105 const int pos_end = BitPos##size(end); \
106 const uint##size active_range = \
107 bits[offset_start] & OneRange##size(pos_start, pos_end); \
108 if (active_range) { \
109 return BitShift##size(offset_start) + \
110 LeastSignificantBitPosition##size(active_range); \
114 const uint##size start_mask = \
115 bits[offset_start] & IntervalUp##size(pos_start); \
117 return BitShift##size(offset_start) + \
118 LeastSignificantBitPosition##size(start_mask); \
120 for (int offset = offset_start + 1; offset < offset_end; ++offset) { \
121 if (bits[offset]) { \
122 return BitShift##size(offset) + \
123 LeastSignificantBitPosition##size(bits[offset]); \
126 const int pos_end = BitPos##size(end); \
127 const uint##size active_range = \
128 bits[offset_end] & IntervalDown##size(pos_end); \
129 if (active_range) { \
130 return BitShift##size(offset_end) + \
131 LeastSignificantBitPosition##size(active_range); \
142 #undef LEAST_SIGNIFCANT_BIT_POSITION
144 #define MOST_SIGNIFICANT_BIT_POSITION(size) \
145 int##size MostSignificantBitPosition##size( \
146 const uint##size* const bits, uint##size start, uint##size end) { \
147 DCHECK_GE(end, start); \
148 if (IsBitSet##size(bits, end)) { \
151 const int offset_start = BitOffset##size(start); \
152 const int offset_end = BitOffset##size(end); \
153 const int pos_end = BitPos##size(end); \
154 if (offset_start == offset_end) { \
155 const int pos_start = BitPos##size(start); \
156 const uint##size active_range = \
157 bits[offset_start] & OneRange##size(pos_start, pos_end); \
158 if (active_range) { \
159 return BitShift##size(offset_end) + \
160 MostSignificantBitPosition##size(active_range); \
165 const uint##size end_mask = \
166 bits[offset_end] & IntervalDown##size(pos_end); \
168 return BitShift##size(offset_end) + \
169 MostSignificantBitPosition##size(end_mask); \
171 for (int offset = offset_end - 1; offset > offset_start; --offset) { \
172 if (bits[offset]) { \
173 return BitShift##size(offset) + \
174 MostSignificantBitPosition##size(bits[offset]); \
177 const int pos_start = BitPos##size(start); \
178 const uint##size active_range = \
179 bits[offset_start] & IntervalUp##size(pos_start); \
180 if (active_range) { \
181 return BitShift##size(offset_start) + \
182 MostSignificantBitPosition##size(active_range); \
193 #undef MOST_SIGNIFICANT_BIT_POSITION
195 #define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size) \
196 int##size UnsafeLeastSignificantBitPosition##size( \
197 const uint##size* const bits, uint##size start, uint##size end) { \
198 DCHECK_LE(start, end); \
199 DCHECK(IsBitSet##size(bits, end)); \
200 if (IsBitSet##size(bits, start)) { \
203 const int offset_start = BitOffset##size(start); \
204 const int offset_end = BitOffset##size(end); \
205 const int pos_start = BitPos##size(start); \
206 const uint##size start_mask = \
207 bits[offset_start] & IntervalUp##size(pos_start); \
209 return BitShift##size(offset_start) + \
210 LeastSignificantBitPosition##size(start_mask); \
212 for (int offset = offset_start + 1; offset <= offset_end; ++offset) { \
213 if (bits[offset]) { \
214 return BitShift##size(offset) + \
215 LeastSignificantBitPosition##size(bits[offset]); \
224 #undef UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION
226 #define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size) \
227 int##size UnsafeMostSignificantBitPosition##size( \
228 const uint##size* const bits, uint##size start, uint##size end) { \
229 DCHECK_GE(end, start); \
230 DCHECK(IsBitSet##size(bits, start)); \
231 if (IsBitSet##size(bits, end)) { \
234 const int offset_start = BitOffset##size(start); \
235 const int offset_end = BitOffset##size(end); \
236 const int pos_end = BitPos##size(end); \
237 const uint##size end_mask = \
238 bits[offset_end] & IntervalDown##size(pos_end); \
240 return BitShift##size(offset_end) + \
241 MostSignificantBitPosition##size(end_mask); \
243 for (int offset = offset_end - 1; offset >= offset_start; --offset) { \
244 if (bits[offset]) { \
245 return BitShift##size(offset) + \
246 MostSignificantBitPosition##size(bits[offset]); \
255 #undef UNSAFE_MOST_SIGNIFICANT_BIT_POSITION
#define UNSAFE_LEAST_SIGNIFICANT_BIT_POSITION(size)
ABSL_FLAG(int, bitset_small_bitset_count, 8, "threshold to count bits with buckets")
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
#define MOST_SIGNIFICANT_BIT_POSITION(size)
#define IS_EMPTY_RANGE(size)
#define BIT_COUNT_RANGE(size, zero)
#define LEAST_SIGNIFCANT_BIT_POSITION(size)
#define UNSAFE_MOST_SIGNIFICANT_BIT_POSITION(size)