Coverage Report

Created: 2025-07-12 06:07

/src/croaring/include/roaring/roaring.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * An implementation of Roaring Bitmaps in C.
3
 */
4
5
#ifndef ROARING_H
6
#define ROARING_H
7
8
#include <stdbool.h>
9
#include <stddef.h>  // for `size_t`
10
#include <stdint.h>
11
12
#include <roaring/roaring_types.h>
13
14
// Include other headers after roaring_types.h
15
#include <roaring/bitset/bitset.h>
16
#include <roaring/memory.h>
17
#include <roaring/portability.h>
18
#include <roaring/roaring_version.h>
19
20
#ifdef __cplusplus
21
extern "C" {
22
namespace roaring {
23
namespace api {
24
#endif
25
26
typedef struct roaring_bitmap_s {
27
    roaring_array_t high_low_container;
28
} roaring_bitmap_t;
29
30
/**
31
 * Dynamically allocates a new bitmap (initially empty).
32
 * Returns NULL if the allocation fails.
33
 * Capacity is a performance hint for how many "containers" the data will need.
34
 * Client is responsible for calling `roaring_bitmap_free()`.
35
 */
36
roaring_bitmap_t *roaring_bitmap_create_with_capacity(uint32_t cap);
37
38
/**
39
 * Dynamically allocates a new bitmap (initially empty).
40
 * Returns NULL if the allocation fails.
41
 * Client is responsible for calling `roaring_bitmap_free()`.
42
 */
43
0
inline roaring_bitmap_t *roaring_bitmap_create(void) {
44
0
    return roaring_bitmap_create_with_capacity(0);
45
0
}
46
47
/**
48
 * Initialize a roaring bitmap structure in memory controlled by client.
49
 * Capacity is a performance hint for how many "containers" the data will need.
50
 * Can return false if auxiliary allocations fail when capacity greater than 0.
51
 */
52
bool roaring_bitmap_init_with_capacity(roaring_bitmap_t *r, uint32_t cap);
53
54
/**
55
 * Initialize a roaring bitmap structure in memory controlled by client.
56
 * The bitmap will be in a "clear" state, with no auxiliary allocations.
57
 * Since this performs no allocations, the function will not fail.
58
 */
59
26.8k
inline void roaring_bitmap_init_cleared(roaring_bitmap_t *r) {
60
26.8k
    roaring_bitmap_init_with_capacity(r, 0);
61
26.8k
}
62
63
/**
64
 * Add all the values between min (included) and max (excluded) that are at a
65
 * distance k*step from min.
66
 * The returned pointer may be NULL in case of errors.
67
 */
68
roaring_bitmap_t *roaring_bitmap_from_range(uint64_t min, uint64_t max,
69
                                            uint32_t step);
70
71
/**
72
 * Creates a new bitmap from a pointer of uint32_t integers
73
 * The returned pointer may be NULL in case of errors.
74
 */
75
roaring_bitmap_t *roaring_bitmap_of_ptr(size_t n_args, const uint32_t *vals);
76
77
/*
78
 * Whether you want to use copy-on-write.
79
 * Saves memory and avoids copies, but needs more care in a threaded context.
80
 * Most users should ignore this flag.
81
 *
82
 * Note: If you do turn this flag to 'true', enabling COW, then ensure that you
83
 * do so for all of your bitmaps, since interactions between bitmaps with and
84
 * without COW is unsafe.
85
 */
86
10.7k
inline bool roaring_bitmap_get_copy_on_write(const roaring_bitmap_t *r) {
87
10.7k
    return r->high_low_container.flags & ROARING_FLAG_COW;
88
10.7k
}
89
49.5k
inline void roaring_bitmap_set_copy_on_write(roaring_bitmap_t *r, bool cow) {
90
49.5k
    if (cow) {
91
0
        r->high_low_container.flags |= ROARING_FLAG_COW;
92
49.5k
    } else {
93
49.5k
        r->high_low_container.flags &= ~ROARING_FLAG_COW;
94
49.5k
    }
95
49.5k
}
96
97
/**
98
 * Return a copy of the bitmap with all values shifted by offset.
99
 * The returned pointer may be NULL in case of errors. The caller is responsible
100
 * for freeing the return bitmap.
101
 */
102
roaring_bitmap_t *roaring_bitmap_add_offset(const roaring_bitmap_t *bm,
103
                                            int64_t offset);
104
/**
105
 * Describe the inner structure of the bitmap.
106
 */
107
void roaring_bitmap_printf_describe(const roaring_bitmap_t *r);
108
109
/**
110
 * Creates a new bitmap from a list of uint32_t integers
111
 *
112
 * This function is deprecated, use `roaring_bitmap_from` instead, which
113
 * doesn't require the number of elements to be passed in.
114
 *
115
 * @see roaring_bitmap_from
116
 */
117
CROARING_DEPRECATED roaring_bitmap_t *roaring_bitmap_of(size_t n, ...);
118
119
#ifdef __cplusplus
120
/**
121
 * Creates a new bitmap which contains all values passed in as arguments.
122
 *
123
 * To create a bitmap from a variable number of arguments, use the
124
 * `roaring_bitmap_of_ptr` function instead.
125
 */
126
// Use an immediately invoked closure, capturing by reference
127
// (in case __VA_ARGS__ refers to context outside the closure)
128
// Include a 0 at the beginning of the array to make the array length > 0
129
// (zero sized arrays are not valid in standard c/c++)
130
#define roaring_bitmap_from(...)                                              \
131
    [&]() {                                                                   \
132
        const uint32_t roaring_bitmap_from_array[] = {0, __VA_ARGS__};        \
133
        return roaring_bitmap_of_ptr((sizeof(roaring_bitmap_from_array) /     \
134
                                      sizeof(roaring_bitmap_from_array[0])) - \
135
                                         1,                                   \
136
                                     &roaring_bitmap_from_array[1]);          \
137
    }()
138
#else
139
/**
140
 * Creates a new bitmap which contains all values passed in as arguments.
141
 *
142
 * To create a bitmap from a variable number of arguments, use the
143
 * `roaring_bitmap_of_ptr` function instead.
144
 */
145
// While __VA_ARGS__ occurs twice in expansion, one of the times is in a sizeof
146
// expression, which is an unevaluated context, so it's even safe in the case
147
// where expressions passed have side effects (roaring64_bitmap_from(my_func(),
148
// ++i))
149
// Include a 0 at the beginning of the array to make the array length > 0
150
// (zero sized arrays are not valid in standard c/c++)
151
#define roaring_bitmap_from(...)                                             \
152
    roaring_bitmap_of_ptr(                                                   \
153
        (sizeof((const uint32_t[]){0, __VA_ARGS__}) / sizeof(uint32_t)) - 1, \
154
        &((const uint32_t[]){0, __VA_ARGS__})[1])
155
#endif
156
157
/**
158
 * Copies a bitmap (this does memory allocation).
159
 * The caller is responsible for memory management.
160
 * The returned pointer may be NULL in case of errors.
161
 */
162
roaring_bitmap_t *roaring_bitmap_copy(const roaring_bitmap_t *r);
163
164
/**
165
 * Copies a bitmap from src to dest. It is assumed that the pointer dest
166
 * is to an already allocated bitmap. The content of the dest bitmap is
167
 * freed/deleted.
168
 *
169
 * It might be preferable and simpler to call roaring_bitmap_copy except
170
 * that roaring_bitmap_overwrite can save on memory allocations.
171
 *
172
 * Returns true if successful, or false if there was an error. On failure,
173
 * the dest bitmap is left in a valid, empty state (even if it was not empty
174
 * before).
175
 */
176
bool roaring_bitmap_overwrite(roaring_bitmap_t *dest,
177
                              const roaring_bitmap_t *src);
178
179
/**
180
 * Print the content of the bitmap.
181
 */
182
void roaring_bitmap_printf(const roaring_bitmap_t *r);
183
184
/**
185
 * Computes the intersection between two bitmaps and returns new bitmap. The
186
 * caller is responsible for memory management.
187
 *
188
 * Performance hint: if you are computing the intersection between several
189
 * bitmaps, two-by-two, it is best to start with the smallest bitmap.
190
 * You may also rely on roaring_bitmap_and_inplace to avoid creating
191
 * many temporary bitmaps.
192
 * The returned pointer may be NULL in case of errors.
193
 */
194
roaring_bitmap_t *roaring_bitmap_and(const roaring_bitmap_t *r1,
195
                                     const roaring_bitmap_t *r2);
196
197
/**
198
 * Computes the size of the intersection between two bitmaps.
199
 */
200
uint64_t roaring_bitmap_and_cardinality(const roaring_bitmap_t *r1,
201
                                        const roaring_bitmap_t *r2);
202
203
/**
204
 * Check whether two bitmaps intersect.
205
 */
206
bool roaring_bitmap_intersect(const roaring_bitmap_t *r1,
207
                              const roaring_bitmap_t *r2);
208
209
/**
210
 * Check whether a bitmap and an open range intersect.
211
 */
212
bool roaring_bitmap_intersect_with_range(const roaring_bitmap_t *bm, uint64_t x,
213
                                         uint64_t y);
214
215
/**
216
 * Computes the Jaccard index between two bitmaps. (Also known as the Tanimoto
217
 * distance, or the Jaccard similarity coefficient)
218
 *
219
 * The Jaccard index is undefined if both bitmaps are empty.
220
 */
221
double roaring_bitmap_jaccard_index(const roaring_bitmap_t *r1,
222
                                    const roaring_bitmap_t *r2);
223
224
/**
225
 * Computes the size of the union between two bitmaps.
226
 */
227
uint64_t roaring_bitmap_or_cardinality(const roaring_bitmap_t *r1,
228
                                       const roaring_bitmap_t *r2);
229
230
/**
231
 * Computes the size of the difference (andnot) between two bitmaps.
232
 */
233
uint64_t roaring_bitmap_andnot_cardinality(const roaring_bitmap_t *r1,
234
                                           const roaring_bitmap_t *r2);
235
236
/**
237
 * Computes the size of the symmetric difference (xor) between two bitmaps.
238
 */
239
uint64_t roaring_bitmap_xor_cardinality(const roaring_bitmap_t *r1,
240
                                        const roaring_bitmap_t *r2);
241
242
/**
243
 * Inplace version of `roaring_bitmap_and()`, modifies r1
244
 * r1 == r2 is allowed.
245
 *
246
 * Performance hint: if you are computing the intersection between several
247
 * bitmaps, two-by-two, it is best to start with the smallest bitmap.
248
 */
249
void roaring_bitmap_and_inplace(roaring_bitmap_t *r1,
250
                                const roaring_bitmap_t *r2);
251
252
/**
253
 * Computes the union between two bitmaps and returns new bitmap. The caller is
254
 * responsible for memory management.
255
 * The returned pointer may be NULL in case of errors.
256
 */
257
roaring_bitmap_t *roaring_bitmap_or(const roaring_bitmap_t *r1,
258
                                    const roaring_bitmap_t *r2);
259
260
/**
261
 * Inplace version of `roaring_bitmap_or(), modifies r1.
262
 * TODO: decide whether r1 == r2 ok
263
 */
264
void roaring_bitmap_or_inplace(roaring_bitmap_t *r1,
265
                               const roaring_bitmap_t *r2);
266
267
/**
268
 * Compute the union of 'number' bitmaps.
269
 * Caller is responsible for freeing the result.
270
 * See also `roaring_bitmap_or_many_heap()`
271
 * The returned pointer may be NULL in case of errors.
272
 */
273
roaring_bitmap_t *roaring_bitmap_or_many(size_t number,
274
                                         const roaring_bitmap_t **rs);
275
276
/**
277
 * Compute the union of 'number' bitmaps using a heap. This can sometimes be
278
 * faster than `roaring_bitmap_or_many() which uses a naive algorithm.
279
 * Caller is responsible for freeing the result.
280
 */
281
roaring_bitmap_t *roaring_bitmap_or_many_heap(uint32_t number,
282
                                              const roaring_bitmap_t **rs);
283
284
/**
285
 * Computes the symmetric difference (xor) between two bitmaps
286
 * and returns new bitmap. The caller is responsible for memory management.
287
 * The returned pointer may be NULL in case of errors.
288
 */
289
roaring_bitmap_t *roaring_bitmap_xor(const roaring_bitmap_t *r1,
290
                                     const roaring_bitmap_t *r2);
291
292
/**
293
 * Inplace version of roaring_bitmap_xor, modifies r1, r1 != r2.
294
 */
295
void roaring_bitmap_xor_inplace(roaring_bitmap_t *r1,
296
                                const roaring_bitmap_t *r2);
297
298
/**
299
 * Compute the xor of 'number' bitmaps.
300
 * Caller is responsible for freeing the result.
301
 * The returned pointer may be NULL in case of errors.
302
 */
303
roaring_bitmap_t *roaring_bitmap_xor_many(size_t number,
304
                                          const roaring_bitmap_t **rs);
305
306
/**
307
 * Computes the difference (andnot) between two bitmaps and returns new bitmap.
308
 * Caller is responsible for freeing the result.
309
 * The returned pointer may be NULL in case of errors.
310
 */
311
roaring_bitmap_t *roaring_bitmap_andnot(const roaring_bitmap_t *r1,
312
                                        const roaring_bitmap_t *r2);
313
314
/**
315
 * Inplace version of roaring_bitmap_andnot, modifies r1, r1 != r2.
316
 */
317
void roaring_bitmap_andnot_inplace(roaring_bitmap_t *r1,
318
                                   const roaring_bitmap_t *r2);
319
320
/**
321
 * TODO: consider implementing:
322
 *
323
 * "Compute the xor of 'number' bitmaps using a heap. This can sometimes be
324
 *  faster than roaring_bitmap_xor_many which uses a naive algorithm. Caller is
325
 *  responsible for freeing the result.""
326
 *
327
 * roaring_bitmap_t *roaring_bitmap_xor_many_heap(uint32_t number,
328
 *                                                const roaring_bitmap_t **rs);
329
 */
330
331
/**
332
 * Frees the memory.
333
 */
334
void roaring_bitmap_free(const roaring_bitmap_t *r);
335
336
/**
337
 * A bit of context usable with `roaring_bitmap_*_bulk()` functions
338
 *
339
 * Should be initialized with `{0}` (or `memset()` to all zeros).
340
 * Callers should treat it as an opaque type.
341
 *
342
 * A context may only be used with a single bitmap
343
 * (unless re-initialized to zero), and any modification to a bitmap
344
 * (other than modifications performed with `_bulk()` functions with the context
345
 * passed) will invalidate any contexts associated with that bitmap.
346
 */
347
typedef struct roaring_bulk_context_s {
348
    ROARING_CONTAINER_T *container;
349
    int idx;
350
    uint16_t key;
351
    uint8_t typecode;
352
} roaring_bulk_context_t;
353
354
/**
355
 * Add an item, using context from a previous insert for speed optimization.
356
 *
357
 * `context` will be used to store information between calls to make bulk
358
 * operations faster. `*context` should be zero-initialized before the first
359
 * call to this function.
360
 *
361
 * Modifying the bitmap in any way (other than `-bulk` suffixed functions)
362
 * will invalidate the stored context, calling this function with a non-zero
363
 * context after doing any modification invokes undefined behavior.
364
 *
365
 * In order to exploit this optimization, the caller should call this function
366
 * with values with the same "key" (high 16 bits of the value) consecutively.
367
 */
368
void roaring_bitmap_add_bulk(roaring_bitmap_t *r,
369
                             roaring_bulk_context_t *context, uint32_t val);
370
371
/**
372
 * Add value n_args from pointer vals, faster than repeatedly calling
373
 * `roaring_bitmap_add()`
374
 *
375
 * In order to exploit this optimization, the caller should attempt to keep
376
 * values with the same "key" (high 16 bits of the value) as consecutive
377
 * elements in `vals`
378
 */
379
void roaring_bitmap_add_many(roaring_bitmap_t *r, size_t n_args,
380
                             const uint32_t *vals);
381
382
/**
383
 * Add value x
384
 */
385
void roaring_bitmap_add(roaring_bitmap_t *r, uint32_t x);
386
387
/**
388
 * Add value x
389
 * Returns true if a new value was added, false if the value already existed.
390
 */
391
bool roaring_bitmap_add_checked(roaring_bitmap_t *r, uint32_t x);
392
393
/**
394
 * Add all values in range [min, max]
395
 */
396
void roaring_bitmap_add_range_closed(roaring_bitmap_t *r, uint32_t min,
397
                                     uint32_t max);
398
399
/**
400
 * Add all values in range [min, max)
401
 */
402
inline void roaring_bitmap_add_range(roaring_bitmap_t *r, uint64_t min,
403
5.36k
                                     uint64_t max) {
404
5.36k
    if (max <= min || min > (uint64_t)UINT32_MAX + 1) {
405
2.95k
        return;
406
2.95k
    }
407
2.41k
    roaring_bitmap_add_range_closed(r, (uint32_t)min, (uint32_t)(max - 1));
408
2.41k
}
409
410
/**
411
 * Remove value x
412
 */
413
void roaring_bitmap_remove(roaring_bitmap_t *r, uint32_t x);
414
415
/**
416
 * Remove all values in range [min, max]
417
 */
418
void roaring_bitmap_remove_range_closed(roaring_bitmap_t *r, uint32_t min,
419
                                        uint32_t max);
420
421
/**
422
 * Remove all values in range [min, max)
423
 */
424
inline void roaring_bitmap_remove_range(roaring_bitmap_t *r, uint64_t min,
425
5.36k
                                        uint64_t max) {
426
5.36k
    if (max <= min || min > (uint64_t)UINT32_MAX + 1) {
427
4.42k
        return;
428
4.42k
    }
429
937
    roaring_bitmap_remove_range_closed(r, (uint32_t)min, (uint32_t)(max - 1));
430
937
}
431
432
/**
433
 * Remove multiple values
434
 */
435
void roaring_bitmap_remove_many(roaring_bitmap_t *r, size_t n_args,
436
                                const uint32_t *vals);
437
438
/**
439
 * Remove value x
440
 * Returns true if a new value was removed, false if the value was not existing.
441
 */
442
bool roaring_bitmap_remove_checked(roaring_bitmap_t *r, uint32_t x);
443
444
/**
445
 * Check if value is present
446
 */
447
bool roaring_bitmap_contains(const roaring_bitmap_t *r, uint32_t val);
448
449
/**
450
 * Check whether a range of values from range_start (included)
451
 * to range_end (excluded) is present
452
 */
453
bool roaring_bitmap_contains_range(const roaring_bitmap_t *r,
454
                                   uint64_t range_start, uint64_t range_end);
455
456
/**
457
 * Check whether a range of values from range_start (included)
458
 * to range_end (included) is present
459
 */
460
bool roaring_bitmap_contains_range_closed(const roaring_bitmap_t *r,
461
                                          uint32_t range_start,
462
                                          uint32_t range_end);
463
464
/**
465
 * Check if an items is present, using context from a previous insert or search
466
 * for speed optimization.
467
 *
468
 * `context` will be used to store information between calls to make bulk
469
 * operations faster. `*context` should be zero-initialized before the first
470
 * call to this function.
471
 *
472
 * Modifying the bitmap in any way (other than `-bulk` suffixed functions)
473
 * will invalidate the stored context, calling this function with a non-zero
474
 * context after doing any modification invokes undefined behavior.
475
 *
476
 * In order to exploit this optimization, the caller should call this function
477
 * with values with the same "key" (high 16 bits of the value) consecutively.
478
 */
479
bool roaring_bitmap_contains_bulk(const roaring_bitmap_t *r,
480
                                  roaring_bulk_context_t *context,
481
                                  uint32_t val);
482
483
/**
484
 * Get the cardinality of the bitmap (number of elements).
485
 */
486
uint64_t roaring_bitmap_get_cardinality(const roaring_bitmap_t *r);
487
488
/**
489
 * Returns the number of elements in the range [range_start, range_end).
490
 */
491
uint64_t roaring_bitmap_range_cardinality(const roaring_bitmap_t *r,
492
                                          uint64_t range_start,
493
                                          uint64_t range_end);
494
495
/**
496
 * Returns the number of elements in the range [range_start, range_end].
497
 */
498
uint64_t roaring_bitmap_range_cardinality_closed(const roaring_bitmap_t *r,
499
                                                 uint32_t range_start,
500
                                                 uint32_t range_end);
501
/**
502
 * Returns true if the bitmap is empty (cardinality is zero).
503
 */
504
bool roaring_bitmap_is_empty(const roaring_bitmap_t *r);
505
506
/**
507
 * Empties the bitmap.  It will have no auxiliary allocations (so if the bitmap
508
 * was initialized in client memory via roaring_bitmap_init(), then a call to
509
 * roaring_bitmap_clear() would be enough to "free" it)
510
 */
511
void roaring_bitmap_clear(roaring_bitmap_t *r);
512
513
/**
514
 * Convert the bitmap to a sorted array, output in `ans`.
515
 *
516
 * Caller is responsible to ensure that there is enough memory allocated, e.g.
517
 *
518
 *     ans = malloc(roaring_bitmap_get_cardinality(bitmap) * sizeof(uint32_t));
519
 */
520
void roaring_bitmap_to_uint32_array(const roaring_bitmap_t *r, uint32_t *ans);
521
522
/**
523
 * Store the bitmap to a bitset. This can be useful for people
524
 * who need the performance and simplicity of a standard bitset.
525
 * We assume that the input bitset is originally empty (does not
526
 * have any set bit).
527
 *
528
 *   bitset_t * out = bitset_create();
529
 *   // if the bitset has content in it, call "bitset_clear(out)"
530
 *   bool success = roaring_bitmap_to_bitset(mybitmap, out);
531
 *   // on failure, success will be false.
532
 *   // You can then query the bitset:
533
 *   bool is_present = bitset_get(out,  10011 );
534
 *   // you must free the memory:
535
 *   bitset_free(out);
536
 *
537
 */
538
bool roaring_bitmap_to_bitset(const roaring_bitmap_t *r, bitset_t *bitset);
539
540
/**
541
 * Convert the bitmap to a sorted array from `offset` by `limit`, output in
542
 * `ans`.
543
 *
544
 * Caller is responsible to ensure that there is enough memory allocated, e.g.
545
 *
546
 *     ans = malloc(roaring_bitmap_get_cardinality(limit) * sizeof(uint32_t));
547
 *
548
 * Return false in case of failure (e.g., insufficient memory)
549
 */
550
bool roaring_bitmap_range_uint32_array(const roaring_bitmap_t *r, size_t offset,
551
                                       size_t limit, uint32_t *ans);
552
553
/**
554
 * Remove run-length encoding even when it is more space efficient.
555
 * Return whether a change was applied.
556
 */
557
bool roaring_bitmap_remove_run_compression(roaring_bitmap_t *r);
558
559
/**
560
 * Convert array and bitmap containers to run containers when it is more
561
 * efficient; also convert from run containers when more space efficient.
562
 *
563
 * Returns true if the result has at least one run container.
564
 * Additional savings might be possible by calling `shrinkToFit()`.
565
 */
566
bool roaring_bitmap_run_optimize(roaring_bitmap_t *r);
567
568
/**
569
 * If needed, reallocate memory to shrink the memory usage.
570
 * Returns the number of bytes saved.
571
 */
572
size_t roaring_bitmap_shrink_to_fit(roaring_bitmap_t *r);
573
574
/**
575
 * Write the bitmap to an output pointer, this output buffer should refer to
576
 * at least `roaring_bitmap_size_in_bytes(r)` allocated bytes.
577
 *
578
 * See `roaring_bitmap_portable_serialize()` if you want a format that's
579
 * compatible with Java and Go implementations.  This format can sometimes be
580
 * more space efficient than the portable form, e.g. when the data is sparse.
581
 *
582
 * Returns how many bytes written, should be `roaring_bitmap_size_in_bytes(r)`.
583
 *
584
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
585
 * mainframe IBM s390x), the data format is going to be big-endian and not
586
 * compatible with little-endian systems.
587
 *
588
 * When serializing data to a file, we recommend that you also use
589
 * checksums so that, at deserialization, you can be confident
590
 * that you are recovering the correct data.
591
 */
592
size_t roaring_bitmap_serialize(const roaring_bitmap_t *r, char *buf);
593
594
/**
595
 * Use with `roaring_bitmap_serialize()`.
596
 *
597
 * (See `roaring_bitmap_portable_deserialize()` if you want a format that's
598
 * compatible with Java and Go implementations).
599
 *
600
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
601
 * mainframe IBM s390x), the data format is going to be big-endian and not
602
 * compatible with little-endian systems.
603
 *
604
 * The returned pointer may be NULL in case of errors.
605
 */
606
roaring_bitmap_t *roaring_bitmap_deserialize(const void *buf);
607
608
/**
609
 * Use with `roaring_bitmap_serialize()`.
610
 *
611
 * (See `roaring_bitmap_portable_deserialize_safe()` if you want a format that's
612
 * compatible with Java and Go implementations).
613
 *
614
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
615
 * mainframe IBM s390x), the data format is going to be big-endian and not
616
 * compatible with little-endian systems.
617
 *
618
 * The difference with `roaring_bitmap_deserialize()` is that this function
619
 * checks that the input buffer is a valid bitmap.  If the buffer is too small,
620
 * NULL is returned.
621
 *
622
 * The returned pointer may be NULL in case of errors.
623
 */
624
roaring_bitmap_t *roaring_bitmap_deserialize_safe(const void *buf,
625
                                                  size_t maxbytes);
626
627
/**
628
 * How many bytes are required to serialize this bitmap (NOT compatible
629
 * with Java and Go versions)
630
 */
631
size_t roaring_bitmap_size_in_bytes(const roaring_bitmap_t *r);
632
633
/**
634
 * Read bitmap from a serialized buffer.
635
 * In case of failure, NULL is returned.
636
 *
637
 * This function is unsafe in the sense that if there is no valid serialized
638
 * bitmap at the pointer, then many bytes could be read, possibly causing a
639
 * buffer overflow.  See also roaring_bitmap_portable_deserialize_safe().
640
 *
641
 * This is meant to be compatible with the Java and Go versions:
642
 * https://github.com/RoaringBitmap/RoaringFormatSpec
643
 *
644
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
645
 * mainframe IBM s390x), the data format is going to be big-endian and not
646
 * compatible with little-endian systems.
647
 *
648
 * The returned pointer may be NULL in case of errors.
649
 */
650
roaring_bitmap_t *roaring_bitmap_portable_deserialize(const char *buf);
651
652
/**
653
 * Read bitmap from a serialized buffer safely (reading up to maxbytes).
654
 * In case of failure, NULL is returned.
655
 *
656
 * This is meant to be compatible with the Java and Go versions:
657
 * https://github.com/RoaringBitmap/RoaringFormatSpec
658
 *
659
 * The function itself is safe in the sense that it will not cause buffer
660
 * overflows: it will not read beyond the scope of the provided buffer
661
 * (buf,maxbytes).
662
 *
663
 * However, for correct operations, it is assumed that the bitmap
664
 * read was once serialized from a valid bitmap (i.e., it follows the format
665
 * specification). If you provided an incorrect input (garbage), then the bitmap
666
 * read may not be in a valid state and following operations may not lead to
667
 * sensible results. In particular, the serialized array containers need to be
668
 * in sorted order, and the run containers should be in sorted non-overlapping
669
 * order. This is is guaranteed to happen when serializing an existing bitmap,
670
 * but not for random inputs.
671
 *
672
 * If the source is untrusted, you should call
673
 * roaring_bitmap_internal_validate to check the validity of the
674
 * bitmap prior to using it. Only after calling roaring_bitmap_internal_validate
675
 * is the bitmap considered safe for use.
676
 *
677
 * We also recommend that you use checksums to check that serialized data
678
 * corresponds to the serialized bitmap. The CRoaring library does not provide
679
 * checksumming.
680
 *
681
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
682
 * mainframe IBM s390x), the data format is going to be big-endian and not
683
 * compatible with little-endian systems.
684
 *
685
 * The returned pointer may be NULL in case of errors.
686
 */
687
roaring_bitmap_t *roaring_bitmap_portable_deserialize_safe(const char *buf,
688
                                                           size_t maxbytes);
689
690
/**
691
 * Read bitmap from a serialized buffer.
692
 * In case of failure, NULL is returned.
693
 *
694
 * Bitmap returned by this function can be used in all readonly contexts.
695
 * Bitmap must be freed as usual, by calling roaring_bitmap_free().
696
 * Underlying buffer must not be freed or modified while it backs any bitmaps.
697
 *
698
 * The function is unsafe in the following ways:
699
 * 1) It may execute unaligned memory accesses.
700
 * 2) A buffer overflow may occur if buf does not point to a valid serialized
701
 *    bitmap.
702
 *
703
 * This is meant to be compatible with the Java and Go versions:
704
 * https://github.com/RoaringBitmap/RoaringFormatSpec
705
 *
706
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
707
 * mainframe IBM s390x), the data format is going to be big-endian and not
708
 * compatible with little-endian systems.
709
 *
710
 * The returned pointer may be NULL in case of errors.
711
 */
712
roaring_bitmap_t *roaring_bitmap_portable_deserialize_frozen(const char *buf);
713
714
/**
715
 * Check how many bytes would be read (up to maxbytes) at this pointer if there
716
 * is a bitmap, returns zero if there is no valid bitmap.
717
 *
718
 * This is meant to be compatible with the Java and Go versions:
719
 * https://github.com/RoaringBitmap/RoaringFormatSpec
720
 */
721
size_t roaring_bitmap_portable_deserialize_size(const char *buf,
722
                                                size_t maxbytes);
723
724
/**
725
 * How many bytes are required to serialize this bitmap.
726
 *
727
 * This is meant to be compatible with the Java and Go versions:
728
 * https://github.com/RoaringBitmap/RoaringFormatSpec
729
 */
730
size_t roaring_bitmap_portable_size_in_bytes(const roaring_bitmap_t *r);
731
732
/**
733
 * Write a bitmap to a char buffer.  The output buffer should refer to at least
734
 * `roaring_bitmap_portable_size_in_bytes(r)` bytes of allocated memory.
735
 *
736
 * Returns how many bytes were written which should match
737
 * `roaring_bitmap_portable_size_in_bytes(r)`.
738
 *
739
 * This is meant to be compatible with the Java and Go versions:
740
 * https://github.com/RoaringBitmap/RoaringFormatSpec
741
 *
742
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
743
 * mainframe IBM s390x), the data format is going to be big-endian and not
744
 * compatible with little-endian systems.
745
 *
746
 * When serializing data to a file, we recommend that you also use
747
 * checksums so that, at deserialization, you can be confident
748
 * that you are recovering the correct data.
749
 */
750
size_t roaring_bitmap_portable_serialize(const roaring_bitmap_t *r, char *buf);
751
752
/*
753
 * "Frozen" serialization format imitates memory layout of roaring_bitmap_t.
754
 * Deserialized bitmap is a constant view of the underlying buffer.
755
 * This significantly reduces amount of allocations and copying required during
756
 * deserialization.
757
 * It can be used with memory mapped files.
758
 * Example can be found in benchmarks/frozen_benchmark.c
759
 *
760
 *         [#####] const roaring_bitmap_t *
761
 *          | | |
762
 *     +----+ | +-+
763
 *     |      |   |
764
 * [#####################################] underlying buffer
765
 *
766
 * Note that because frozen serialization format imitates C memory layout
767
 * of roaring_bitmap_t, it is not fixed. It is different on big/little endian
768
 * platforms and can be changed in future.
769
 */
770
771
/**
772
 * Returns number of bytes required to serialize bitmap using frozen format.
773
 */
774
size_t roaring_bitmap_frozen_size_in_bytes(const roaring_bitmap_t *r);
775
776
/**
777
 * Serializes bitmap using frozen format.
778
 * Buffer size must be at least roaring_bitmap_frozen_size_in_bytes().
779
 *
780
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
781
 * mainframe IBM s390x), the data format is going to be big-endian and not
782
 * compatible with little-endian systems.
783
 *
784
 * When serializing data to a file, we recommend that you also use
785
 * checksums so that, at deserialization, you can be confident
786
 * that you are recovering the correct data.
787
 */
788
void roaring_bitmap_frozen_serialize(const roaring_bitmap_t *r, char *buf);
789
790
/**
791
 * Creates constant bitmap that is a view of a given buffer.
792
 * Buffer data should have been written by `roaring_bitmap_frozen_serialize()`
793
 * Its beginning must also be aligned by 32 bytes.
794
 * Length must be equal exactly to `roaring_bitmap_frozen_size_in_bytes()`.
795
 * In case of failure, NULL is returned.
796
 *
797
 * Bitmap returned by this function can be used in all readonly contexts.
798
 * Bitmap must be freed as usual, by calling roaring_bitmap_free().
799
 * Underlying buffer must not be freed or modified while it backs any bitmaps.
800
 *
801
 * This function is endian-sensitive. If you have a big-endian system (e.g., a
802
 * mainframe IBM s390x), the data format is going to be big-endian and not
803
 * compatible with little-endian systems.
804
 */
805
const roaring_bitmap_t *roaring_bitmap_frozen_view(const char *buf,
806
                                                   size_t length);
807
808
/**
809
 * Iterate over the bitmap elements. The function iterator is called once for
810
 * all the values with ptr (can be NULL) as the second parameter of each call.
811
 *
812
 * `roaring_iterator` is simply a pointer to a function that returns bool
813
 * (true means that the iteration should continue while false means that it
814
 * should stop), and takes (uint32_t,void*) as inputs.
815
 *
816
 * Returns true if the roaring_iterator returned true throughout (so that all
817
 * data points were necessarily visited).
818
 *
819
 * Iteration is ordered: from the smallest to the largest elements.
820
 */
821
bool roaring_iterate(const roaring_bitmap_t *r, roaring_iterator iterator,
822
                     void *ptr);
823
824
bool roaring_iterate64(const roaring_bitmap_t *r, roaring_iterator64 iterator,
825
                       uint64_t high_bits, void *ptr);
826
827
/**
828
 * Return true if the two bitmaps contain the same elements.
829
 */
830
bool roaring_bitmap_equals(const roaring_bitmap_t *r1,
831
                           const roaring_bitmap_t *r2);
832
833
/**
834
 * Return true if all the elements of r1 are also in r2.
835
 */
836
bool roaring_bitmap_is_subset(const roaring_bitmap_t *r1,
837
                              const roaring_bitmap_t *r2);
838
839
/**
840
 * Return true if all the elements of r1 are also in r2, and r2 is strictly
841
 * greater than r1.
842
 */
843
bool roaring_bitmap_is_strict_subset(const roaring_bitmap_t *r1,
844
                                     const roaring_bitmap_t *r2);
845
846
/**
847
 * (For expert users who seek high performance.)
848
 *
849
 * Computes the union between two bitmaps and returns new bitmap. The caller is
850
 * responsible for memory management.
851
 *
852
 * The lazy version defers some computations such as the maintenance of the
853
 * cardinality counts. Thus you must call `roaring_bitmap_repair_after_lazy()`
854
 * after executing "lazy" computations.
855
 *
856
 * It is safe to repeatedly call roaring_bitmap_lazy_or_inplace on the result.
857
 *
858
 * `bitsetconversion` is a flag which determines whether container-container
859
 * operations force a bitset conversion.
860
 *
861
 * The returned pointer may be NULL in case of errors.
862
 */
863
roaring_bitmap_t *roaring_bitmap_lazy_or(const roaring_bitmap_t *r1,
864
                                         const roaring_bitmap_t *r2,
865
                                         const bool bitsetconversion);
866
867
/**
868
 * (For expert users who seek high performance.)
869
 *
870
 * Inplace version of roaring_bitmap_lazy_or, modifies r1.
871
 *
872
 * `bitsetconversion` is a flag which determines whether container-container
873
 * operations force a bitset conversion.
874
 */
875
void roaring_bitmap_lazy_or_inplace(roaring_bitmap_t *r1,
876
                                    const roaring_bitmap_t *r2,
877
                                    const bool bitsetconversion);
878
879
/**
880
 * (For expert users who seek high performance.)
881
 *
882
 * Execute maintenance on a bitmap created from `roaring_bitmap_lazy_or()`
883
 * or modified with `roaring_bitmap_lazy_or_inplace()`.
884
 */
885
void roaring_bitmap_repair_after_lazy(roaring_bitmap_t *r1);
886
887
/**
888
 * Computes the symmetric difference between two bitmaps and returns new bitmap.
889
 * The caller is responsible for memory management.
890
 *
891
 * The lazy version defers some computations such as the maintenance of the
892
 * cardinality counts. Thus you must call `roaring_bitmap_repair_after_lazy()`
893
 * after executing "lazy" computations.
894
 *
895
 * It is safe to repeatedly call `roaring_bitmap_lazy_xor_inplace()` on
896
 * the result.
897
 *
898
 * The returned pointer may be NULL in case of errors.
899
 */
900
roaring_bitmap_t *roaring_bitmap_lazy_xor(const roaring_bitmap_t *r1,
901
                                          const roaring_bitmap_t *r2);
902
903
/**
904
 * (For expert users who seek high performance.)
905
 *
906
 * Inplace version of roaring_bitmap_lazy_xor, modifies r1. r1 != r2
907
 */
908
void roaring_bitmap_lazy_xor_inplace(roaring_bitmap_t *r1,
909
                                     const roaring_bitmap_t *r2);
910
911
/**
912
 * Compute the negation of the bitmap in the interval [range_start, range_end).
913
 * The number of negated values is range_end - range_start.
914
 * Areas outside the range are passed through unchanged.
915
 * The returned pointer may be NULL in case of errors.
916
 */
917
roaring_bitmap_t *roaring_bitmap_flip(const roaring_bitmap_t *r1,
918
                                      uint64_t range_start, uint64_t range_end);
919
920
/**
921
 * Compute the negation of the bitmap in the interval [range_start, range_end].
922
 * The number of negated values is range_end - range_start + 1.
923
 * Areas outside the range are passed through unchanged.
924
 * The returned pointer may be NULL in case of errors.
925
 */
926
roaring_bitmap_t *roaring_bitmap_flip_closed(const roaring_bitmap_t *x1,
927
                                             uint32_t range_start,
928
                                             uint32_t range_end);
929
/**
930
 * compute (in place) the negation of the roaring bitmap within a specified
931
 * interval: [range_start, range_end). The number of negated values is
932
 * range_end - range_start.
933
 * Areas outside the range are passed through unchanged.
934
 */
935
void roaring_bitmap_flip_inplace(roaring_bitmap_t *r1, uint64_t range_start,
936
                                 uint64_t range_end);
937
938
/**
939
 * compute (in place) the negation of the roaring bitmap within a specified
940
 * interval: [range_start, range_end]. The number of negated values is
941
 * range_end - range_start + 1.
942
 * Areas outside the range are passed through unchanged.
943
 */
944
void roaring_bitmap_flip_inplace_closed(roaring_bitmap_t *r1,
945
                                        uint32_t range_start,
946
                                        uint32_t range_end);
947
948
/**
949
 * Selects the element at index 'rank' where the smallest element is at index 0.
950
 * If the size of the roaring bitmap is strictly greater than rank, then this
951
 * function returns true and sets element to the element of given rank.
952
 * Otherwise, it returns false.
953
 */
954
bool roaring_bitmap_select(const roaring_bitmap_t *r, uint32_t rank,
955
                           uint32_t *element);
956
957
/**
958
 * roaring_bitmap_rank returns the number of integers that are smaller or equal
959
 * to x. Thus if x is the first element, this function will return 1. If
960
 * x is smaller than the smallest element, this function will return 0.
961
 *
962
 * The indexing convention differs between roaring_bitmap_select and
963
 * roaring_bitmap_rank: roaring_bitmap_select refers to the smallest value
964
 * as having index 0, whereas roaring_bitmap_rank returns 1 when ranking
965
 * the smallest value.
966
 */
967
uint64_t roaring_bitmap_rank(const roaring_bitmap_t *r, uint32_t x);
968
969
/**
970
 * roaring_bitmap_rank_many is an `Bulk` version of `roaring_bitmap_rank`
971
 * it puts rank value of each element in `[begin .. end)` to `ans[]`
972
 *
973
 * the values in `[begin .. end)` must be sorted in Ascending order;
974
 * Caller is responsible to ensure that there is enough memory allocated, e.g.
975
 *
976
 *     ans = malloc((end-begin) * sizeof(uint64_t));
977
 */
978
void roaring_bitmap_rank_many(const roaring_bitmap_t *r, const uint32_t *begin,
979
                              const uint32_t *end, uint64_t *ans);
980
981
/**
982
 * Returns the index of x in the given roaring bitmap.
983
 * If the roaring bitmap doesn't contain x , this function will return -1.
984
 * The difference with rank function is that this function will return -1 when x
985
 * is not the element of roaring bitmap, but the rank function will return a
986
 * non-negative number.
987
 */
988
int64_t roaring_bitmap_get_index(const roaring_bitmap_t *r, uint32_t x);
989
990
/**
991
 * Returns the smallest value in the set, or UINT32_MAX if the set is empty.
992
 */
993
uint32_t roaring_bitmap_minimum(const roaring_bitmap_t *r);
994
995
/**
996
 * Returns the greatest value in the set, or 0 if the set is empty.
997
 */
998
uint32_t roaring_bitmap_maximum(const roaring_bitmap_t *r);
999
1000
/**
1001
 * (For advanced users.)
1002
 *
1003
 * Collect statistics about the bitmap, see roaring_types.h for
1004
 * a description of roaring_statistics_t
1005
 */
1006
void roaring_bitmap_statistics(const roaring_bitmap_t *r,
1007
                               roaring_statistics_t *stat);
1008
1009
/**
1010
 * Perform internal consistency checks. Returns true if the bitmap is
1011
 * consistent. It may be useful to call this after deserializing bitmaps from
1012
 * untrusted sources. If roaring_bitmap_internal_validate returns true, then the
1013
 * bitmap should be consistent and can be trusted not to cause crashes or memory
1014
 * corruption.
1015
 *
1016
 * Note that some operations intentionally leave bitmaps in an inconsistent
1017
 * state temporarily, for example, `roaring_bitmap_lazy_*` functions, until
1018
 * `roaring_bitmap_repair_after_lazy` is called.
1019
 *
1020
 * If reason is non-null, it will be set to a string describing the first
1021
 * inconsistency found if any.
1022
 */
1023
bool roaring_bitmap_internal_validate(const roaring_bitmap_t *r,
1024
                                      const char **reason);
1025
1026
/*********************
1027
* What follows is code use to iterate through values in a roaring bitmap
1028
1029
roaring_bitmap_t *r =...
1030
roaring_uint32_iterator_t i;
1031
roaring_iterator_create(r, &i);
1032
while(i.has_value) {
1033
  printf("value = %d\n", i.current_value);
1034
  roaring_uint32_iterator_advance(&i);
1035
}
1036
1037
Obviously, if you modify the underlying bitmap, the iterator
1038
becomes invalid. So don't.
1039
*/
1040
1041
/**
1042
 * A struct used to keep iterator state. Users should only access
1043
 * `current_value` and `has_value`, the rest of the type should be treated as
1044
 * opaque.
1045
 */
1046
typedef struct roaring_uint32_iterator_s {
1047
    const roaring_bitmap_t *parent;        // Owner
1048
    const ROARING_CONTAINER_T *container;  // Current container
1049
    uint8_t typecode;                      // Typecode of current container
1050
    int32_t container_index;               // Current container index
1051
    uint32_t highbits;                     // High 16 bits of the current value
1052
    roaring_container_iterator_t container_it;
1053
1054
    uint32_t current_value;
1055
    bool has_value;
1056
} roaring_uint32_iterator_t;
1057
1058
/**
1059
 * Initialize an iterator object that can be used to iterate through the values.
1060
 * If there is a  value, then this iterator points to the first value and
1061
 * `it->has_value` is true. The value is in `it->current_value`.
1062
 */
1063
void roaring_iterator_init(const roaring_bitmap_t *r,
1064
                           roaring_uint32_iterator_t *newit);
1065
1066
/** DEPRECATED, use `roaring_iterator_init`. */
1067
CROARING_DEPRECATED static inline void roaring_init_iterator(
1068
0
    const roaring_bitmap_t *r, roaring_uint32_iterator_t *newit) {
1069
0
    roaring_iterator_init(r, newit);
1070
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_init_iterator(roaring::api::roaring_bitmap_s const*, roaring::api::roaring_uint32_iterator_s*)
Unexecuted instantiation: roaring.c:roaring_init_iterator
1071
1072
/**
1073
 * Initialize an iterator object that can be used to iterate through the values.
1074
 * If there is a value, then this iterator points to the last value and
1075
 * `it->has_value` is true. The value is in `it->current_value`.
1076
 */
1077
void roaring_iterator_init_last(const roaring_bitmap_t *r,
1078
                                roaring_uint32_iterator_t *newit);
1079
1080
/** DEPRECATED, use `roaring_iterator_init_last`. */
1081
CROARING_DEPRECATED static inline void roaring_init_iterator_last(
1082
0
    const roaring_bitmap_t *r, roaring_uint32_iterator_t *newit) {
1083
0
    roaring_iterator_init_last(r, newit);
1084
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_init_iterator_last(roaring::api::roaring_bitmap_s const*, roaring::api::roaring_uint32_iterator_s*)
Unexecuted instantiation: roaring.c:roaring_init_iterator_last
1085
1086
/**
1087
 * Create an iterator object that can be used to iterate through the values.
1088
 * Caller is responsible for calling `roaring_free_iterator()`.
1089
 *
1090
 * The iterator is initialized (this function calls `roaring_iterator_init()`)
1091
 * If there is a value, then this iterator points to the first value and
1092
 * `it->has_value` is true.  The value is in `it->current_value`.
1093
 */
1094
roaring_uint32_iterator_t *roaring_iterator_create(const roaring_bitmap_t *r);
1095
1096
/** DEPRECATED, use `roaring_iterator_create`. */
1097
CROARING_DEPRECATED static inline roaring_uint32_iterator_t *
1098
0
roaring_create_iterator(const roaring_bitmap_t *r) {
1099
0
    return roaring_iterator_create(r);
1100
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_create_iterator(roaring::api::roaring_bitmap_s const*)
Unexecuted instantiation: roaring.c:roaring_create_iterator
1101
1102
/**
1103
 * Advance the iterator. If there is a new value, then `it->has_value` is true.
1104
 * The new value is in `it->current_value`. Values are traversed in increasing
1105
 * orders. For convenience, returns `it->has_value`.
1106
 *
1107
 * Once `it->has_value` is false, `roaring_uint32_iterator_advance` should not
1108
 * be called on the iterator again. Calling `roaring_uint32_iterator_previous`
1109
 * is allowed.
1110
 */
1111
bool roaring_uint32_iterator_advance(roaring_uint32_iterator_t *it);
1112
1113
/** DEPRECATED, use `roaring_uint32_iterator_advance`. */
1114
CROARING_DEPRECATED static inline bool roaring_advance_uint32_iterator(
1115
0
    roaring_uint32_iterator_t *it) {
1116
0
    return roaring_uint32_iterator_advance(it);
1117
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_advance_uint32_iterator(roaring::api::roaring_uint32_iterator_s*)
Unexecuted instantiation: roaring.c:roaring_advance_uint32_iterator
1118
1119
/**
1120
 * Decrement the iterator. If there's a new value, then `it->has_value` is true.
1121
 * The new value is in `it->current_value`. Values are traversed in decreasing
1122
 * order. For convenience, returns `it->has_value`.
1123
 *
1124
 * Once `it->has_value` is false, `roaring_uint32_iterator_previous` should not
1125
 * be called on the iterator again. Calling `roaring_uint32_iterator_advance` is
1126
 * allowed.
1127
 */
1128
bool roaring_uint32_iterator_previous(roaring_uint32_iterator_t *it);
1129
1130
/** DEPRECATED, use `roaring_uint32_iterator_previous`. */
1131
CROARING_DEPRECATED static inline bool roaring_previous_uint32_iterator(
1132
0
    roaring_uint32_iterator_t *it) {
1133
0
    return roaring_uint32_iterator_previous(it);
1134
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_previous_uint32_iterator(roaring::api::roaring_uint32_iterator_s*)
Unexecuted instantiation: roaring.c:roaring_previous_uint32_iterator
1135
1136
/**
1137
 * Move the iterator to the first value >= `val`. If there is a such a value,
1138
 * then `it->has_value` is true. The new value is in `it->current_value`.
1139
 * For convenience, returns `it->has_value`.
1140
 */
1141
bool roaring_uint32_iterator_move_equalorlarger(roaring_uint32_iterator_t *it,
1142
                                                uint32_t val);
1143
1144
/** DEPRECATED, use `roaring_uint32_iterator_move_equalorlarger`. */
1145
CROARING_DEPRECATED static inline bool
1146
roaring_move_uint32_iterator_equalorlarger(roaring_uint32_iterator_t *it,
1147
0
                                           uint32_t val) {
1148
0
    return roaring_uint32_iterator_move_equalorlarger(it, val);
1149
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_move_uint32_iterator_equalorlarger(roaring::api::roaring_uint32_iterator_s*, unsigned int)
Unexecuted instantiation: roaring.c:roaring_move_uint32_iterator_equalorlarger
1150
1151
/**
1152
 * Creates a copy of an iterator.
1153
 * Caller must free it.
1154
 */
1155
roaring_uint32_iterator_t *roaring_uint32_iterator_copy(
1156
    const roaring_uint32_iterator_t *it);
1157
1158
/** DEPRECATED, use `roaring_uint32_iterator_copy`. */
1159
CROARING_DEPRECATED static inline roaring_uint32_iterator_t *
1160
0
roaring_copy_uint32_iterator(const roaring_uint32_iterator_t *it) {
1161
0
    return roaring_uint32_iterator_copy(it);
1162
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_copy_uint32_iterator(roaring::api::roaring_uint32_iterator_s const*)
Unexecuted instantiation: roaring.c:roaring_copy_uint32_iterator
1163
1164
/**
1165
 * Free memory following `roaring_iterator_create()`
1166
 */
1167
void roaring_uint32_iterator_free(roaring_uint32_iterator_t *it);
1168
1169
/** DEPRECATED, use `roaring_uint32_iterator_free`. */
1170
CROARING_DEPRECATED static inline void roaring_free_uint32_iterator(
1171
0
    roaring_uint32_iterator_t *it) {
1172
0
    roaring_uint32_iterator_free(it);
1173
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_free_uint32_iterator(roaring::api::roaring_uint32_iterator_s*)
Unexecuted instantiation: roaring.c:roaring_free_uint32_iterator
1174
1175
/*
1176
 * Reads next ${count} values from iterator into user-supplied ${buf}.
1177
 * Returns the number of read elements.
1178
 * This number can be smaller than ${count}, which means that iterator is
1179
 * drained.
1180
 *
1181
 * This function satisfies semantics of iteration and can be used together with
1182
 * other iterator functions.
1183
 *  - first value is copied from ${it}->current_value
1184
 *  - after function returns, iterator is positioned at the next element
1185
 */
1186
uint32_t roaring_uint32_iterator_read(roaring_uint32_iterator_t *it,
1187
                                      uint32_t *buf, uint32_t count);
1188
1189
/** DEPRECATED, use `roaring_uint32_iterator_read`. */
1190
CROARING_DEPRECATED static inline uint32_t roaring_read_uint32_iterator(
1191
0
    roaring_uint32_iterator_t *it, uint32_t *buf, uint32_t count) {
1192
0
    return roaring_uint32_iterator_read(it, buf, count);
1193
0
}
Unexecuted instantiation: croaring_fuzzer_cc.cc:roaring::api::roaring_read_uint32_iterator(roaring::api::roaring_uint32_iterator_s*, unsigned int*, unsigned int)
Unexecuted instantiation: roaring.c:roaring_read_uint32_iterator
1194
1195
#ifdef __cplusplus
1196
}
1197
}
1198
}  // extern "C" { namespace roaring { namespace api {
1199
#endif
1200
1201
#endif /* ROARING_H */
1202
1203
#ifdef __cplusplus
1204
/**
1205
 * Best practices for C++ headers is to avoid polluting global scope.
1206
 * But for C compatibility when just `roaring.h` is included building as
1207
 * C++, default to global access for the C public API.
1208
 *
1209
 * BUT when `roaring.hh` is included instead, it sets this flag.  That way
1210
 * explicit namespacing must be used to get the C functions.
1211
 *
1212
 * This is outside the include guard so that if you include BOTH headers,
1213
 * the order won't matter; you still get the global definitions.
1214
 */
1215
#if !defined(ROARING_API_NOT_IN_GLOBAL_NAMESPACE)
1216
using namespace ::roaring::api;
1217
#endif
1218
#endif
1219
1220
// roaring64 will include roaring.h, but we would
1221
// prefer to avoid having our users include roaring64.h
1222
// in addition to roaring.h.
1223
#include <roaring/roaring64.h>