Coverage Report

Created: 2026-05-30 06:48

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