/var/local/thirdparty/installed/include/roaring/containers/bitset.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * bitset.h |
3 | | * |
4 | | */ |
5 | | |
6 | | #ifndef INCLUDE_CONTAINERS_BITSET_H_ |
7 | | #define INCLUDE_CONTAINERS_BITSET_H_ |
8 | | |
9 | | #include <stdbool.h> |
10 | | #include <stdint.h> |
11 | | |
12 | | #include <roaring/portability.h> |
13 | | #include <roaring/roaring_types.h> // roaring_iterator |
14 | | #include <roaring/utilasm.h> // ASM_XXX macros |
15 | | |
16 | | #include <roaring/containers/container_defs.h> // container_t, perfparameters |
17 | | |
18 | | #ifdef __cplusplus |
19 | | extern "C" { namespace roaring { |
20 | | |
21 | | // Note: in pure C++ code, you should avoid putting `using` in header files |
22 | | using api::roaring_iterator; |
23 | | using api::roaring_iterator64; |
24 | | |
25 | | namespace internal { |
26 | | #endif |
27 | | |
28 | | |
29 | | |
30 | | enum { |
31 | | BITSET_CONTAINER_SIZE_IN_WORDS = (1 << 16) / 64, |
32 | | BITSET_UNKNOWN_CARDINALITY = -1 |
33 | | }; |
34 | | |
35 | | STRUCT_CONTAINER(bitset_container_s) { |
36 | | int32_t cardinality; |
37 | | uint64_t *words; |
38 | | }; |
39 | | |
40 | | typedef struct bitset_container_s bitset_container_t; |
41 | | |
42 | | #define CAST_bitset(c) CAST(bitset_container_t *, c) // safer downcast |
43 | | #define const_CAST_bitset(c) CAST(const bitset_container_t *, c) |
44 | | #define movable_CAST_bitset(c) movable_CAST(bitset_container_t **, c) |
45 | | |
46 | | /* Create a new bitset. Return NULL in case of failure. */ |
47 | | bitset_container_t *bitset_container_create(void); |
48 | | |
49 | | /* Free memory. */ |
50 | | void bitset_container_free(bitset_container_t *bitset); |
51 | | |
52 | | /* Clear bitset (sets bits to 0). */ |
53 | | void bitset_container_clear(bitset_container_t *bitset); |
54 | | |
55 | | /* Set all bits to 1. */ |
56 | | void bitset_container_set_all(bitset_container_t *bitset); |
57 | | |
58 | | /* Duplicate bitset */ |
59 | | bitset_container_t *bitset_container_clone(const bitset_container_t *src); |
60 | | |
61 | | /* Set the bit in [begin,end). WARNING: as of April 2016, this method is slow |
62 | | * and |
63 | | * should not be used in performance-sensitive code. Ever. */ |
64 | | void bitset_container_set_range(bitset_container_t *bitset, uint32_t begin, |
65 | | uint32_t end); |
66 | | |
67 | | #if defined(CROARING_ASMBITMANIPOPTIMIZATION) && defined(__AVX2__) |
68 | | /* Set the ith bit. */ |
69 | | static inline void bitset_container_set(bitset_container_t *bitset, |
70 | | uint16_t pos) { |
71 | | uint64_t shift = 6; |
72 | | uint64_t offset; |
73 | | uint64_t p = pos; |
74 | | ASM_SHIFT_RIGHT(p, shift, offset); |
75 | | uint64_t load = bitset->words[offset]; |
76 | | ASM_SET_BIT_INC_WAS_CLEAR(load, p, bitset->cardinality); |
77 | | bitset->words[offset] = load; |
78 | | } |
79 | | |
80 | | /* Unset the ith bit. Currently unused. Could be used for optimization. */ |
81 | | /*static inline void bitset_container_unset(bitset_container_t *bitset, |
82 | | uint16_t pos) { |
83 | | uint64_t shift = 6; |
84 | | uint64_t offset; |
85 | | uint64_t p = pos; |
86 | | ASM_SHIFT_RIGHT(p, shift, offset); |
87 | | uint64_t load = bitset->words[offset]; |
88 | | ASM_CLEAR_BIT_DEC_WAS_SET(load, p, bitset->cardinality); |
89 | | bitset->words[offset] = load; |
90 | | }*/ |
91 | | |
92 | | /* Add `pos' to `bitset'. Returns true if `pos' was not present. Might be slower |
93 | | * than bitset_container_set. */ |
94 | | static inline bool bitset_container_add(bitset_container_t *bitset, |
95 | | uint16_t pos) { |
96 | | uint64_t shift = 6; |
97 | | uint64_t offset; |
98 | | uint64_t p = pos; |
99 | | ASM_SHIFT_RIGHT(p, shift, offset); |
100 | | uint64_t load = bitset->words[offset]; |
101 | | // could be possibly slightly further optimized |
102 | | const int32_t oldcard = bitset->cardinality; |
103 | | ASM_SET_BIT_INC_WAS_CLEAR(load, p, bitset->cardinality); |
104 | | bitset->words[offset] = load; |
105 | | return bitset->cardinality - oldcard; |
106 | | } |
107 | | |
108 | | /* Remove `pos' from `bitset'. Returns true if `pos' was present. Might be |
109 | | * slower than bitset_container_unset. */ |
110 | | static inline bool bitset_container_remove(bitset_container_t *bitset, |
111 | | uint16_t pos) { |
112 | | uint64_t shift = 6; |
113 | | uint64_t offset; |
114 | | uint64_t p = pos; |
115 | | ASM_SHIFT_RIGHT(p, shift, offset); |
116 | | uint64_t load = bitset->words[offset]; |
117 | | // could be possibly slightly further optimized |
118 | | const int32_t oldcard = bitset->cardinality; |
119 | | ASM_CLEAR_BIT_DEC_WAS_SET(load, p, bitset->cardinality); |
120 | | bitset->words[offset] = load; |
121 | | return oldcard - bitset->cardinality; |
122 | | } |
123 | | |
124 | | /* Get the value of the ith bit. */ |
125 | | inline bool bitset_container_get(const bitset_container_t *bitset, |
126 | | uint16_t pos) { |
127 | | uint64_t word = bitset->words[pos >> 6]; |
128 | | const uint64_t p = pos; |
129 | | ASM_INPLACESHIFT_RIGHT(word, p); |
130 | | return word & 1; |
131 | | } |
132 | | |
133 | | #else |
134 | | |
135 | | /* Set the ith bit. */ |
136 | | static inline void bitset_container_set(bitset_container_t *bitset, |
137 | 0 | uint16_t pos) { |
138 | 0 | const uint64_t old_word = bitset->words[pos >> 6]; |
139 | 0 | const int index = pos & 63; |
140 | 0 | const uint64_t new_word = old_word | (UINT64_C(1) << index); |
141 | 0 | bitset->cardinality += (uint32_t)((old_word ^ new_word) >> index); |
142 | 0 | bitset->words[pos >> 6] = new_word; |
143 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL20bitset_container_setEPNS0_18bitset_container_sEt Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL20bitset_container_setEPNS0_18bitset_container_sEt Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL20bitset_container_setEPNS0_18bitset_container_sEt Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL20bitset_container_setEPNS0_18bitset_container_sEt Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL20bitset_container_setEPNS0_18bitset_container_sEt Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL20bitset_container_setEPNS0_18bitset_container_sEt Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL20bitset_container_setEPNS0_18bitset_container_sEt |
144 | | |
145 | | /* Unset the ith bit. Currently unused. */ |
146 | | /*static inline void bitset_container_unset(bitset_container_t *bitset, |
147 | | uint16_t pos) { |
148 | | const uint64_t old_word = bitset->words[pos >> 6]; |
149 | | const int index = pos & 63; |
150 | | const uint64_t new_word = old_word & (~(UINT64_C(1) << index)); |
151 | | bitset->cardinality -= (uint32_t)((old_word ^ new_word) >> index); |
152 | | bitset->words[pos >> 6] = new_word; |
153 | | }*/ |
154 | | |
155 | | /* Add `pos' to `bitset'. Returns true if `pos' was not present. Might be slower |
156 | | * than bitset_container_set. */ |
157 | | static inline bool bitset_container_add(bitset_container_t *bitset, |
158 | 0 | uint16_t pos) { |
159 | 0 | const uint64_t old_word = bitset->words[pos >> 6]; |
160 | 0 | const int index = pos & 63; |
161 | 0 | const uint64_t new_word = old_word | (UINT64_C(1) << index); |
162 | 0 | const uint64_t increment = (old_word ^ new_word) >> index; |
163 | 0 | bitset->cardinality += (uint32_t)increment; |
164 | 0 | bitset->words[pos >> 6] = new_word; |
165 | 0 | return increment > 0; |
166 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL20bitset_container_addEPNS0_18bitset_container_sEt Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL20bitset_container_addEPNS0_18bitset_container_sEt Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL20bitset_container_addEPNS0_18bitset_container_sEt Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL20bitset_container_addEPNS0_18bitset_container_sEt Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL20bitset_container_addEPNS0_18bitset_container_sEt Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL20bitset_container_addEPNS0_18bitset_container_sEt Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL20bitset_container_addEPNS0_18bitset_container_sEt |
167 | | |
168 | | /* Remove `pos' from `bitset'. Returns true if `pos' was present. Might be |
169 | | * slower than bitset_container_unset. */ |
170 | | static inline bool bitset_container_remove(bitset_container_t *bitset, |
171 | 0 | uint16_t pos) { |
172 | 0 | const uint64_t old_word = bitset->words[pos >> 6]; |
173 | 0 | const int index = pos & 63; |
174 | 0 | const uint64_t new_word = old_word & (~(UINT64_C(1) << index)); |
175 | 0 | const uint64_t increment = (old_word ^ new_word) >> index; |
176 | 0 | bitset->cardinality -= (uint32_t)increment; |
177 | 0 | bitset->words[pos >> 6] = new_word; |
178 | 0 | return increment > 0; |
179 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL23bitset_container_removeEPNS0_18bitset_container_sEt Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL23bitset_container_removeEPNS0_18bitset_container_sEt Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL23bitset_container_removeEPNS0_18bitset_container_sEt Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL23bitset_container_removeEPNS0_18bitset_container_sEt Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL23bitset_container_removeEPNS0_18bitset_container_sEt Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL23bitset_container_removeEPNS0_18bitset_container_sEt Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL23bitset_container_removeEPNS0_18bitset_container_sEt |
180 | | |
181 | | /* Get the value of the ith bit. */ |
182 | | inline bool bitset_container_get(const bitset_container_t *bitset, |
183 | 0 | uint16_t pos) { |
184 | 0 | const uint64_t word = bitset->words[pos >> 6]; |
185 | 0 | return (word >> (pos & 63)) & 1; |
186 | 0 | } |
187 | | |
188 | | #endif |
189 | | |
190 | | /* |
191 | | * Check if all bits are set in a range of positions from pos_start (included) to |
192 | | * pos_end (excluded). |
193 | | */ |
194 | | static inline bool bitset_container_get_range(const bitset_container_t *bitset, |
195 | 0 | uint32_t pos_start, uint32_t pos_end) { |
196 | 0 |
|
197 | 0 | const uint32_t start = pos_start >> 6; |
198 | 0 | const uint32_t end = pos_end >> 6; |
199 | 0 |
|
200 | 0 | const uint64_t first = ~((1ULL << (pos_start & 0x3F)) - 1); |
201 | 0 | const uint64_t last = (1ULL << (pos_end & 0x3F)) - 1; |
202 | 0 |
|
203 | 0 | if (start == end) return ((bitset->words[end] & first & last) == (first & last)); |
204 | 0 | if ((bitset->words[start] & first) != first) return false; |
205 | 0 |
|
206 | 0 | if ((end < BITSET_CONTAINER_SIZE_IN_WORDS) && ((bitset->words[end] & last) != last)){ |
207 | 0 |
|
208 | 0 | return false; |
209 | 0 | } |
210 | 0 |
|
211 | 0 | for (uint32_t i = start + 1; (i < BITSET_CONTAINER_SIZE_IN_WORDS) && (i < end); ++i){ |
212 | 0 |
|
213 | 0 | if (bitset->words[i] != UINT64_C(0xFFFFFFFFFFFFFFFF)) return false; |
214 | 0 | } |
215 | 0 |
|
216 | 0 | return true; |
217 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL26bitset_container_get_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL26bitset_container_get_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL26bitset_container_get_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL26bitset_container_get_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL26bitset_container_get_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL26bitset_container_get_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL26bitset_container_get_rangeEPKNS0_18bitset_container_sEjj |
218 | | |
219 | | /* Check whether `bitset' is present in `array'. Calls bitset_container_get. */ |
220 | | inline bool bitset_container_contains(const bitset_container_t *bitset, |
221 | 0 | uint16_t pos) { |
222 | 0 | return bitset_container_get(bitset, pos); |
223 | 0 | } |
224 | | |
225 | | /* |
226 | | * Check whether a range of bits from position `pos_start' (included) to `pos_end' (excluded) |
227 | | * is present in `bitset'. Calls bitset_container_get_all. |
228 | | */ |
229 | | static inline bool bitset_container_contains_range(const bitset_container_t *bitset, |
230 | 0 | uint32_t pos_start, uint32_t pos_end) { |
231 | 0 | return bitset_container_get_range(bitset, pos_start, pos_end); |
232 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL31bitset_container_contains_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL31bitset_container_contains_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL31bitset_container_contains_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL31bitset_container_contains_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL31bitset_container_contains_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL31bitset_container_contains_rangeEPKNS0_18bitset_container_sEjj Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL31bitset_container_contains_rangeEPKNS0_18bitset_container_sEjj |
233 | | |
234 | | /* Get the number of bits set */ |
235 | | ALLOW_UNALIGNED |
236 | | static inline int bitset_container_cardinality( |
237 | 0 | const bitset_container_t *bitset) { |
238 | 0 | return bitset->cardinality; |
239 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL28bitset_container_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL28bitset_container_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL28bitset_container_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL28bitset_container_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL28bitset_container_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL28bitset_container_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL28bitset_container_cardinalityEPKNS0_18bitset_container_sE |
240 | | |
241 | | |
242 | | |
243 | | |
244 | | /* Copy one container into another. We assume that they are distinct. */ |
245 | | void bitset_container_copy(const bitset_container_t *source, |
246 | | bitset_container_t *dest); |
247 | | |
248 | | /* Add all the values [min,max) at a distance k*step from min: min, |
249 | | * min+step,.... */ |
250 | | void bitset_container_add_from_range(bitset_container_t *bitset, uint32_t min, |
251 | | uint32_t max, uint16_t step); |
252 | | |
253 | | /* Get the number of bits set (force computation). This does not modify bitset. |
254 | | * To update the cardinality, you should do |
255 | | * bitset->cardinality = bitset_container_compute_cardinality(bitset).*/ |
256 | | int bitset_container_compute_cardinality(const bitset_container_t *bitset); |
257 | | |
258 | | /* Check whether this bitset is empty, |
259 | | * it never modifies the bitset struct. */ |
260 | | static inline bool bitset_container_empty( |
261 | 0 | const bitset_container_t *bitset) { |
262 | 0 | if (bitset->cardinality == BITSET_UNKNOWN_CARDINALITY) { |
263 | 0 | for (int i = 0; i < BITSET_CONTAINER_SIZE_IN_WORDS; i ++) { |
264 | 0 | if((bitset->words[i]) != 0) return false; |
265 | 0 | } |
266 | 0 | return true; |
267 | 0 | } |
268 | 0 | return bitset->cardinality == 0; |
269 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL22bitset_container_emptyEPKNS0_18bitset_container_sE Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL22bitset_container_emptyEPKNS0_18bitset_container_sE Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL22bitset_container_emptyEPKNS0_18bitset_container_sE Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL22bitset_container_emptyEPKNS0_18bitset_container_sE Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL22bitset_container_emptyEPKNS0_18bitset_container_sE Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL22bitset_container_emptyEPKNS0_18bitset_container_sE Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL22bitset_container_emptyEPKNS0_18bitset_container_sE |
270 | | |
271 | | |
272 | | /* Get whether there is at least one bit set (see bitset_container_empty for the reverse), |
273 | | the bitset is never modified */ |
274 | | static inline bool bitset_container_const_nonzero_cardinality( |
275 | 0 | const bitset_container_t *bitset) { |
276 | 0 | return !bitset_container_empty(bitset); |
277 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL42bitset_container_const_nonzero_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL42bitset_container_const_nonzero_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL42bitset_container_const_nonzero_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL42bitset_container_const_nonzero_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL42bitset_container_const_nonzero_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL42bitset_container_const_nonzero_cardinalityEPKNS0_18bitset_container_sE Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL42bitset_container_const_nonzero_cardinalityEPKNS0_18bitset_container_sE |
278 | | |
279 | | /* |
280 | | * Check whether the two bitsets intersect |
281 | | */ |
282 | | bool bitset_container_intersect(const bitset_container_t *src_1, |
283 | | const bitset_container_t *src_2); |
284 | | |
285 | | /* Computes the union of bitsets `src_1' and `src_2' into `dst' and return the |
286 | | * cardinality. */ |
287 | | int bitset_container_or(const bitset_container_t *src_1, |
288 | | const bitset_container_t *src_2, |
289 | | bitset_container_t *dst); |
290 | | |
291 | | /* Computes the union of bitsets `src_1' and `src_2' and return the cardinality. |
292 | | */ |
293 | | int bitset_container_or_justcard(const bitset_container_t *src_1, |
294 | | const bitset_container_t *src_2); |
295 | | |
296 | | /* Computes the union of bitsets `src_1' and `src_2' into `dst' and return the |
297 | | * cardinality. Same as bitset_container_or. */ |
298 | | int bitset_container_union(const bitset_container_t *src_1, |
299 | | const bitset_container_t *src_2, |
300 | | bitset_container_t *dst); |
301 | | |
302 | | /* Computes the union of bitsets `src_1' and `src_2' and return the |
303 | | * cardinality. Same as bitset_container_or_justcard. */ |
304 | | int bitset_container_union_justcard(const bitset_container_t *src_1, |
305 | | const bitset_container_t *src_2); |
306 | | |
307 | | /* Computes the union of bitsets `src_1' and `src_2' into `dst', but does |
308 | | * not update the cardinality. Provided to optimize chained operations. */ |
309 | | int bitset_container_union_nocard(const bitset_container_t *src_1, |
310 | | const bitset_container_t *src_2, |
311 | | bitset_container_t *dst); |
312 | | |
313 | | /* Computes the union of bitsets `src_1' and `src_2' into `dst', but does not |
314 | | * update the cardinality. Provided to optimize chained operations. */ |
315 | | int bitset_container_or_nocard(const bitset_container_t *src_1, |
316 | | const bitset_container_t *src_2, |
317 | | bitset_container_t *dst); |
318 | | |
319 | | /* Computes the intersection of bitsets `src_1' and `src_2' into `dst' and |
320 | | * return the cardinality. */ |
321 | | int bitset_container_and(const bitset_container_t *src_1, |
322 | | const bitset_container_t *src_2, |
323 | | bitset_container_t *dst); |
324 | | |
325 | | /* Computes the intersection of bitsets `src_1' and `src_2' and return the |
326 | | * cardinality. */ |
327 | | int bitset_container_and_justcard(const bitset_container_t *src_1, |
328 | | const bitset_container_t *src_2); |
329 | | |
330 | | /* Computes the intersection of bitsets `src_1' and `src_2' into `dst' and |
331 | | * return the cardinality. Same as bitset_container_and. */ |
332 | | int bitset_container_intersection(const bitset_container_t *src_1, |
333 | | const bitset_container_t *src_2, |
334 | | bitset_container_t *dst); |
335 | | |
336 | | /* Computes the intersection of bitsets `src_1' and `src_2' and return the |
337 | | * cardinality. Same as bitset_container_and_justcard. */ |
338 | | int bitset_container_intersection_justcard(const bitset_container_t *src_1, |
339 | | const bitset_container_t *src_2); |
340 | | |
341 | | /* Computes the intersection of bitsets `src_1' and `src_2' into `dst', but does |
342 | | * not update the cardinality. Provided to optimize chained operations. */ |
343 | | int bitset_container_intersection_nocard(const bitset_container_t *src_1, |
344 | | const bitset_container_t *src_2, |
345 | | bitset_container_t *dst); |
346 | | |
347 | | /* Computes the intersection of bitsets `src_1' and `src_2' into `dst', but does |
348 | | * not update the cardinality. Provided to optimize chained operations. */ |
349 | | int bitset_container_and_nocard(const bitset_container_t *src_1, |
350 | | const bitset_container_t *src_2, |
351 | | bitset_container_t *dst); |
352 | | |
353 | | /* Computes the exclusive or of bitsets `src_1' and `src_2' into `dst' and |
354 | | * return the cardinality. */ |
355 | | int bitset_container_xor(const bitset_container_t *src_1, |
356 | | const bitset_container_t *src_2, |
357 | | bitset_container_t *dst); |
358 | | |
359 | | /* Computes the exclusive or of bitsets `src_1' and `src_2' and return the |
360 | | * cardinality. */ |
361 | | int bitset_container_xor_justcard(const bitset_container_t *src_1, |
362 | | const bitset_container_t *src_2); |
363 | | |
364 | | /* Computes the exclusive or of bitsets `src_1' and `src_2' into `dst', but does |
365 | | * not update the cardinality. Provided to optimize chained operations. */ |
366 | | int bitset_container_xor_nocard(const bitset_container_t *src_1, |
367 | | const bitset_container_t *src_2, |
368 | | bitset_container_t *dst); |
369 | | |
370 | | /* Computes the and not of bitsets `src_1' and `src_2' into `dst' and return the |
371 | | * cardinality. */ |
372 | | int bitset_container_andnot(const bitset_container_t *src_1, |
373 | | const bitset_container_t *src_2, |
374 | | bitset_container_t *dst); |
375 | | |
376 | | /* Computes the and not of bitsets `src_1' and `src_2' and return the |
377 | | * cardinality. */ |
378 | | int bitset_container_andnot_justcard(const bitset_container_t *src_1, |
379 | | const bitset_container_t *src_2); |
380 | | |
381 | | /* Computes the and not or of bitsets `src_1' and `src_2' into `dst', but does |
382 | | * not update the cardinality. Provided to optimize chained operations. */ |
383 | | int bitset_container_andnot_nocard(const bitset_container_t *src_1, |
384 | | const bitset_container_t *src_2, |
385 | | bitset_container_t *dst); |
386 | | |
387 | | void bitset_container_offset(const bitset_container_t *c, |
388 | | container_t **loc, container_t **hic, |
389 | | uint16_t offset); |
390 | | /* |
391 | | * Write out the 16-bit integers contained in this container as a list of 32-bit |
392 | | * integers using base |
393 | | * as the starting value (it might be expected that base has zeros in its 16 |
394 | | * least significant bits). |
395 | | * The function returns the number of values written. |
396 | | * The caller is responsible for allocating enough memory in out. |
397 | | * The out pointer should point to enough memory (the cardinality times 32 |
398 | | * bits). |
399 | | */ |
400 | | int bitset_container_to_uint32_array(uint32_t *out, |
401 | | const bitset_container_t *bc, |
402 | | uint32_t base); |
403 | | |
404 | | /* |
405 | | * Print this container using printf (useful for debugging). |
406 | | */ |
407 | | void bitset_container_printf(const bitset_container_t *v); |
408 | | |
409 | | /* |
410 | | * Print this container using printf as a comma-separated list of 32-bit |
411 | | * integers starting at base. |
412 | | */ |
413 | | void bitset_container_printf_as_uint32_array(const bitset_container_t *v, |
414 | | uint32_t base); |
415 | | |
416 | | bool bitset_container_validate(const bitset_container_t *v, const char **reason); |
417 | | |
418 | | /** |
419 | | * Return the serialized size in bytes of a container. |
420 | | */ |
421 | 0 | static inline int32_t bitset_container_serialized_size_in_bytes(void) { |
422 | 0 | return BITSET_CONTAINER_SIZE_IN_WORDS * 8; |
423 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL41bitset_container_serialized_size_in_bytesEv Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL41bitset_container_serialized_size_in_bytesEv Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL41bitset_container_serialized_size_in_bytesEv Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL41bitset_container_serialized_size_in_bytesEv Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL41bitset_container_serialized_size_in_bytesEv Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL41bitset_container_serialized_size_in_bytesEv Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL41bitset_container_serialized_size_in_bytesEv |
424 | | |
425 | | /** |
426 | | * Return the the number of runs. |
427 | | */ |
428 | | int bitset_container_number_of_runs(bitset_container_t *bc); |
429 | | |
430 | | bool bitset_container_iterate(const bitset_container_t *cont, uint32_t base, |
431 | | roaring_iterator iterator, void *ptr); |
432 | | bool bitset_container_iterate64(const bitset_container_t *cont, uint32_t base, |
433 | | roaring_iterator64 iterator, uint64_t high_bits, |
434 | | void *ptr); |
435 | | |
436 | | /** |
437 | | * Writes the underlying array to buf, outputs how many bytes were written. |
438 | | * This is meant to be byte-by-byte compatible with the Java and Go versions of |
439 | | * Roaring. |
440 | | * The number of bytes written should be |
441 | | * bitset_container_size_in_bytes(container). |
442 | | */ |
443 | | int32_t bitset_container_write(const bitset_container_t *container, char *buf); |
444 | | |
445 | | /** |
446 | | * Reads the instance from buf, outputs how many bytes were read. |
447 | | * This is meant to be byte-by-byte compatible with the Java and Go versions of |
448 | | * Roaring. |
449 | | * The number of bytes read should be bitset_container_size_in_bytes(container). |
450 | | * You need to provide the (known) cardinality. |
451 | | */ |
452 | | int32_t bitset_container_read(int32_t cardinality, |
453 | | bitset_container_t *container, const char *buf); |
454 | | /** |
455 | | * Return the serialized size in bytes of a container (see |
456 | | * bitset_container_write). |
457 | | * This is meant to be compatible with the Java and Go versions of Roaring and |
458 | | * assumes |
459 | | * that the cardinality of the container is already known or can be computed. |
460 | | */ |
461 | | static inline int32_t bitset_container_size_in_bytes( |
462 | 0 | const bitset_container_t *container) { |
463 | 0 | (void)container; |
464 | 0 | return BITSET_CONTAINER_SIZE_IN_WORDS * sizeof(uint64_t); |
465 | 0 | } Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL30bitset_container_size_in_bytesEPKNS0_18bitset_container_sE Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL30bitset_container_size_in_bytesEPKNS0_18bitset_container_sE Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL30bitset_container_size_in_bytesEPKNS0_18bitset_container_sE Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL30bitset_container_size_in_bytesEPKNS0_18bitset_container_sE Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL30bitset_container_size_in_bytesEPKNS0_18bitset_container_sE Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL30bitset_container_size_in_bytesEPKNS0_18bitset_container_sE Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL30bitset_container_size_in_bytesEPKNS0_18bitset_container_sE |
466 | | |
467 | | /** |
468 | | * Return true if the two containers have the same content. |
469 | | */ |
470 | | bool bitset_container_equals(const bitset_container_t *container1, |
471 | | const bitset_container_t *container2); |
472 | | |
473 | | /** |
474 | | * Return true if container1 is a subset of container2. |
475 | | */ |
476 | | bool bitset_container_is_subset(const bitset_container_t *container1, |
477 | | const bitset_container_t *container2); |
478 | | |
479 | | /** |
480 | | * If the element of given rank is in this container, supposing that the first |
481 | | * element has rank start_rank, then the function returns true and sets element |
482 | | * accordingly. |
483 | | * Otherwise, it returns false and update start_rank. |
484 | | */ |
485 | | bool bitset_container_select(const bitset_container_t *container, |
486 | | uint32_t *start_rank, uint32_t rank, |
487 | | uint32_t *element); |
488 | | |
489 | | /* Returns the smallest value (assumes not empty) */ |
490 | | uint16_t bitset_container_minimum(const bitset_container_t *container); |
491 | | |
492 | | /* Returns the largest value (assumes not empty) */ |
493 | | uint16_t bitset_container_maximum(const bitset_container_t *container); |
494 | | |
495 | | /* Returns the number of values equal or smaller than x */ |
496 | | int bitset_container_rank(const bitset_container_t *container, uint16_t x); |
497 | | |
498 | | /* bulk version of bitset_container_rank(); return number of consumed elements */ |
499 | | uint32_t bitset_container_rank_many(const bitset_container_t *container, uint64_t start_rank, |
500 | | const uint32_t* begin, const uint32_t* end, uint64_t* ans); |
501 | | |
502 | | /* Returns the index of x , if not exsist return -1 */ |
503 | | int bitset_container_get_index(const bitset_container_t *container, uint16_t x); |
504 | | |
505 | | /* Returns the index of the first value equal or larger than x, or -1 */ |
506 | | int bitset_container_index_equalorlarger(const bitset_container_t *container, uint16_t x); |
507 | | |
508 | | #ifdef __cplusplus |
509 | | } } } // extern "C" { namespace roaring { namespace internal { |
510 | | #endif |
511 | | |
512 | | #endif /* INCLUDE_CONTAINERS_BITSET_H_ */ |