CRoaring  4.2.1
Roaring bitmaps in C (and C++)
roaring64.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <roaring/memory.h>
#include <roaring/portability.h>
#include <roaring/roaring.h>
#include <roaring/roaring_types.h>

Go to the source code of this file.

Classes

struct  roaring64_bulk_context_s
 

Macros

#define roaring64_bitmap_from(...)
 

Typedefs

typedef struct roaring64_bitmap_s roaring64_bitmap_t
 
typedef struct roaring64_leaf_s roaring64_leaf_t
 
typedef struct roaring64_iterator_s roaring64_iterator_t
 
typedef struct roaring64_bulk_context_s roaring64_bulk_context_t
 

Functions

roaring64_bitmap_troaring64_bitmap_create (void)
 
void roaring64_bitmap_free (roaring64_bitmap_t *r)
 
roaring64_bitmap_troaring64_bitmap_copy (const roaring64_bitmap_t *r)
 
roaring64_bitmap_troaring64_bitmap_of_ptr (size_t n_args, const uint64_t *vals)
 
roaring64_bitmap_troaring64_bitmap_move_from_roaring32 (roaring_bitmap_t *r)
 
roaring64_bitmap_troaring64_bitmap_from_range (uint64_t min, uint64_t max, uint64_t step)
 
void roaring64_bitmap_add (roaring64_bitmap_t *r, uint64_t val)
 
bool roaring64_bitmap_add_checked (roaring64_bitmap_t *r, uint64_t val)
 
void roaring64_bitmap_add_bulk (roaring64_bitmap_t *r, roaring64_bulk_context_t *context, uint64_t val)
 
void roaring64_bitmap_add_many (roaring64_bitmap_t *r, size_t n_args, const uint64_t *vals)
 
void roaring64_bitmap_add_range (roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
void roaring64_bitmap_add_range_closed (roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
void roaring64_bitmap_remove (roaring64_bitmap_t *r, uint64_t val)
 
bool roaring64_bitmap_remove_checked (roaring64_bitmap_t *r, uint64_t val)
 
void roaring64_bitmap_remove_bulk (roaring64_bitmap_t *r, roaring64_bulk_context_t *context, uint64_t val)
 
void roaring64_bitmap_remove_many (roaring64_bitmap_t *r, size_t n_args, const uint64_t *vals)
 
void roaring64_bitmap_remove_range (roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
void roaring64_bitmap_remove_range_closed (roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
void roaring64_bitmap_clear (roaring64_bitmap_t *r)
 
bool roaring64_bitmap_contains (const roaring64_bitmap_t *r, uint64_t val)
 
bool roaring64_bitmap_contains_range (const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
bool roaring64_bitmap_contains_bulk (const roaring64_bitmap_t *r, roaring64_bulk_context_t *context, uint64_t val)
 
bool roaring64_bitmap_select (const roaring64_bitmap_t *r, uint64_t rank, uint64_t *element)
 
uint64_t roaring64_bitmap_rank (const roaring64_bitmap_t *r, uint64_t val)
 
bool roaring64_bitmap_get_index (const roaring64_bitmap_t *r, uint64_t val, uint64_t *out_index)
 
uint64_t roaring64_bitmap_get_cardinality (const roaring64_bitmap_t *r)
 
uint64_t roaring64_bitmap_range_cardinality (const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
uint64_t roaring64_bitmap_range_closed_cardinality (const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
bool roaring64_bitmap_is_empty (const roaring64_bitmap_t *r)
 
uint64_t roaring64_bitmap_minimum (const roaring64_bitmap_t *r)
 
uint64_t roaring64_bitmap_maximum (const roaring64_bitmap_t *r)
 
bool roaring64_bitmap_run_optimize (roaring64_bitmap_t *r)
 
void roaring64_bitmap_statistics (const roaring64_bitmap_t *r, roaring64_statistics_t *stat)
 
bool roaring64_bitmap_internal_validate (const roaring64_bitmap_t *r, const char **reason)
 
bool roaring64_bitmap_equals (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
bool roaring64_bitmap_is_subset (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
bool roaring64_bitmap_is_strict_subset (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
roaring64_bitmap_troaring64_bitmap_and (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
uint64_t roaring64_bitmap_and_cardinality (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
void roaring64_bitmap_and_inplace (roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
bool roaring64_bitmap_intersect (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
bool roaring64_bitmap_intersect_with_range (const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
double roaring64_bitmap_jaccard_index (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
roaring64_bitmap_troaring64_bitmap_or (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
uint64_t roaring64_bitmap_or_cardinality (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
void roaring64_bitmap_or_inplace (roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
roaring64_bitmap_troaring64_bitmap_xor (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
uint64_t roaring64_bitmap_xor_cardinality (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
void roaring64_bitmap_xor_inplace (roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
roaring64_bitmap_troaring64_bitmap_andnot (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
uint64_t roaring64_bitmap_andnot_cardinality (const roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
void roaring64_bitmap_andnot_inplace (roaring64_bitmap_t *r1, const roaring64_bitmap_t *r2)
 
roaring64_bitmap_troaring64_bitmap_flip (const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
roaring64_bitmap_troaring64_bitmap_flip_closed (const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
void roaring64_bitmap_flip_inplace (roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
void roaring64_bitmap_flip_closed_inplace (roaring64_bitmap_t *r, uint64_t min, uint64_t max)
 
size_t roaring64_bitmap_portable_size_in_bytes (const roaring64_bitmap_t *r)
 
size_t roaring64_bitmap_portable_serialize (const roaring64_bitmap_t *r, char *buf)
 
size_t roaring64_bitmap_portable_deserialize_size (const char *buf, size_t maxbytes)
 
roaring64_bitmap_troaring64_bitmap_portable_deserialize_safe (const char *buf, size_t maxbytes)
 
bool roaring64_bitmap_iterate (const roaring64_bitmap_t *r, roaring_iterator64 iterator, void *ptr)
 
void roaring64_bitmap_to_uint64_array (const roaring64_bitmap_t *r, uint64_t *out)
 
roaring64_iterator_troaring64_iterator_create (const roaring64_bitmap_t *r)
 
roaring64_iterator_troaring64_iterator_create_last (const roaring64_bitmap_t *r)
 
void roaring64_iterator_reinit (const roaring64_bitmap_t *r, roaring64_iterator_t *it)
 
void roaring64_iterator_reinit_last (const roaring64_bitmap_t *r, roaring64_iterator_t *it)
 
roaring64_iterator_troaring64_iterator_copy (const roaring64_iterator_t *it)
 
void roaring64_iterator_free (roaring64_iterator_t *it)
 
bool roaring64_iterator_has_value (const roaring64_iterator_t *it)
 
uint64_t roaring64_iterator_value (const roaring64_iterator_t *it)
 
bool roaring64_iterator_advance (roaring64_iterator_t *it)
 
bool roaring64_iterator_previous (roaring64_iterator_t *it)
 
bool roaring64_iterator_move_equalorlarger (roaring64_iterator_t *it, uint64_t val)
 
uint64_t roaring64_iterator_read (roaring64_iterator_t *it, uint64_t *buf, uint64_t count)
 

Macro Definition Documentation

◆ roaring64_bitmap_from

#define roaring64_bitmap_from (   ...)
Value:
(sizeof((const uint64_t[]){0, __VA_ARGS__}) / sizeof(uint64_t)) - 1, \
&((const uint64_t[]){0, __VA_ARGS__})[1])
roaring64_bitmap_t * roaring64_bitmap_of_ptr(size_t n_args, const uint64_t *vals)

Creates a new bitmap which contains all values passed in as arguments.

To create a bitmap from a variable number of arguments, use the roaring64_bitmap_of_ptr function instead.

Definition at line 90 of file roaring64.h.

Typedef Documentation

◆ roaring64_bitmap_t

typedef struct roaring64_bitmap_s roaring64_bitmap_t

Definition at line 1 of file roaring64.h.

◆ roaring64_bulk_context_t

A bit of context usable with roaring64_bitmap_*_bulk() functions.

Should be initialized with {0} (or memset() to all zeros). Callers should treat it as an opaque type.

A context may only be used with a single bitmap (unless re-initialized to zero), and any modification to a bitmap (other than modifications performed with _bulk() functions with the context passed) will invalidate any contexts associated with that bitmap.

◆ roaring64_iterator_t

typedef struct roaring64_iterator_s roaring64_iterator_t

Definition at line 1 of file roaring64.h.

◆ roaring64_leaf_t

typedef struct roaring64_leaf_s roaring64_leaf_t

Definition at line 1 of file roaring64.h.

Function Documentation

◆ roaring64_bitmap_add()

void roaring64_bitmap_add ( roaring64_bitmap_t r,
uint64_t  val 
)

Adds the provided value to the bitmap.

◆ roaring64_bitmap_add_bulk()

void roaring64_bitmap_add_bulk ( roaring64_bitmap_t r,
roaring64_bulk_context_t context,
uint64_t  val 
)

Add an item, using context from a previous insert for faster insertion.

context will be used to store information between calls to make bulk operations faster. *context should be zero-initialized before the first call to this function.

Modifying the bitmap in any way (other than -bulk suffixed functions) will invalidate the stored context, calling this function with a non-zero context after doing any modification invokes undefined behavior.

In order to exploit this optimization, the caller should call this function with values with the same high 48 bits of the value consecutively.

◆ roaring64_bitmap_add_checked()

bool roaring64_bitmap_add_checked ( roaring64_bitmap_t r,
uint64_t  val 
)

Adds the provided value to the bitmap. Returns true if a new value was added, false if the value already existed.

◆ roaring64_bitmap_add_many()

void roaring64_bitmap_add_many ( roaring64_bitmap_t r,
size_t  n_args,
const uint64_t *  vals 
)

Add n_args values from vals, faster than repeatedly calling roaring64_bitmap_add()

In order to exploit this optimization, the caller should attempt to keep values with the same high 48 bits of the value as consecutive elements in vals.

◆ roaring64_bitmap_add_range()

void roaring64_bitmap_add_range ( roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Add all values in range [min, max).

◆ roaring64_bitmap_add_range_closed()

void roaring64_bitmap_add_range_closed ( roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Add all values in range [min, max].

◆ roaring64_bitmap_and()

roaring64_bitmap_t* roaring64_bitmap_and ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the intersection between two bitmaps and returns new bitmap. The caller is responsible for free-ing the result.

Performance hint: if you are computing the intersection between several bitmaps, two-by-two, it is best to start with the smallest bitmaps. You may also rely on roaring64_bitmap_and_inplace to avoid creating many temporary bitmaps.

◆ roaring64_bitmap_and_cardinality()

uint64_t roaring64_bitmap_and_cardinality ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the size of the intersection between two bitmaps.

◆ roaring64_bitmap_and_inplace()

void roaring64_bitmap_and_inplace ( roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

In-place version of roaring64_bitmap_and(), modifies r1. r1 and r2 are allowed to be equal.

Performance hint: if you are computing the intersection between several bitmaps, two-by-two, it is best to start with the smallest bitmaps.

◆ roaring64_bitmap_andnot()

roaring64_bitmap_t* roaring64_bitmap_andnot ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the difference (andnot) between two bitmaps and returns a new bitmap. The caller is responsible for free-ing the result.

◆ roaring64_bitmap_andnot_cardinality()

uint64_t roaring64_bitmap_andnot_cardinality ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the size of the difference (andnot) between two bitmaps.

◆ roaring64_bitmap_andnot_inplace()

void roaring64_bitmap_andnot_inplace ( roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

In-place version of roaring64_bitmap_andnot(), modifies r1. r1 and r2 are not allowed to be equal (that would result in an empty bitmap).

◆ roaring64_bitmap_clear()

void roaring64_bitmap_clear ( roaring64_bitmap_t r)

Empties the bitmap.

◆ roaring64_bitmap_contains()

bool roaring64_bitmap_contains ( const roaring64_bitmap_t r,
uint64_t  val 
)

Returns true if the provided value is present.

◆ roaring64_bitmap_contains_bulk()

bool roaring64_bitmap_contains_bulk ( const roaring64_bitmap_t r,
roaring64_bulk_context_t context,
uint64_t  val 
)

Check if an item is present using context from a previous insert or search for faster search.

context will be used to store information between calls to make bulk operations faster. *context should be zero-initialized before the first call to this function.

Modifying the bitmap in any way (other than -bulk suffixed functions) will invalidate the stored context, calling this function with a non-zero context after doing any modification invokes undefined behavior.

In order to exploit this optimization, the caller should call this function with values with the same high 48 bits of the value consecutively.

◆ roaring64_bitmap_contains_range()

bool roaring64_bitmap_contains_range ( const roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Returns true if all values in the range [min, max) are present.

◆ roaring64_bitmap_copy()

roaring64_bitmap_t* roaring64_bitmap_copy ( const roaring64_bitmap_t r)

Returns a copy of a bitmap.

◆ roaring64_bitmap_create()

roaring64_bitmap_t* roaring64_bitmap_create ( void  )

Dynamically allocates a new bitmap (initially empty). Client is responsible for calling roaring64_bitmap_free().

◆ roaring64_bitmap_equals()

bool roaring64_bitmap_equals ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Return true if the two bitmaps contain the same elements.

◆ roaring64_bitmap_flip()

roaring64_bitmap_t* roaring64_bitmap_flip ( const roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Compute the negation of the bitmap in the interval [min, max). The number of negated values is max - min. Areas outside the range are passed through unchanged.

◆ roaring64_bitmap_flip_closed()

roaring64_bitmap_t* roaring64_bitmap_flip_closed ( const roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Compute the negation of the bitmap in the interval [min, max]. The number of negated values is max - min + 1. Areas outside the range are passed through unchanged.

◆ roaring64_bitmap_flip_closed_inplace()

void roaring64_bitmap_flip_closed_inplace ( roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

In-place version of roaring64_bitmap_flip_closed. Compute the negation of the bitmap in the interval [min, max]. The number of negated values is max - min + 1. Areas outside the range are passed through unchanged.

◆ roaring64_bitmap_flip_inplace()

void roaring64_bitmap_flip_inplace ( roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

In-place version of roaring64_bitmap_flip. Compute the negation of the bitmap in the interval [min, max). The number of negated values is max - min. Areas outside the range are passed through unchanged.

◆ roaring64_bitmap_free()

void roaring64_bitmap_free ( roaring64_bitmap_t r)

◆ roaring64_bitmap_from_range()

roaring64_bitmap_t* roaring64_bitmap_from_range ( uint64_t  min,
uint64_t  max,
uint64_t  step 
)

Create a new bitmap containing all the values in [min, max) that are at a distance k*step from min.

◆ roaring64_bitmap_get_cardinality()

uint64_t roaring64_bitmap_get_cardinality ( const roaring64_bitmap_t r)

Returns the number of values in the bitmap.

◆ roaring64_bitmap_get_index()

bool roaring64_bitmap_get_index ( const roaring64_bitmap_t r,
uint64_t  val,
uint64_t *  out_index 
)

Returns true if the given value is in the bitmap, and sets out_index to the (0-based) index of the value in the bitmap. Returns false if the value is not in the bitmap.

◆ roaring64_bitmap_internal_validate()

bool roaring64_bitmap_internal_validate ( const roaring64_bitmap_t r,
const char **  reason 
)

Perform internal consistency checks.

Returns true if the bitmap is consistent. It may be useful to call this after deserializing bitmaps from untrusted sources. If roaring64_bitmap_internal_validate returns true, then the bitmap is consistent and can be trusted not to cause crashes or memory corruption.

If reason is non-null, it will be set to a string describing the first inconsistency found if any.

◆ roaring64_bitmap_intersect()

bool roaring64_bitmap_intersect ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Check whether two bitmaps intersect.

◆ roaring64_bitmap_intersect_with_range()

bool roaring64_bitmap_intersect_with_range ( const roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Check whether a bitmap intersects the range [min, max).

◆ roaring64_bitmap_is_empty()

bool roaring64_bitmap_is_empty ( const roaring64_bitmap_t r)

Returns true if the bitmap is empty (cardinality is zero).

◆ roaring64_bitmap_is_strict_subset()

bool roaring64_bitmap_is_strict_subset ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Return true if all the elements of r1 are also in r2, and r2 is strictly greater than r1.

◆ roaring64_bitmap_is_subset()

bool roaring64_bitmap_is_subset ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Return true if all the elements of r1 are also in r2.

◆ roaring64_bitmap_iterate()

bool roaring64_bitmap_iterate ( const roaring64_bitmap_t r,
roaring_iterator64  iterator,
void *  ptr 
)

Iterate over the bitmap elements. The function iterator is called once for all the values with ptr (can be NULL) as the second parameter of each call.

roaring_iterator64 is simply a pointer to a function that returns a bool and takes (uint64_t, void*) as inputs. True means that the iteration should continue, while false means that it should stop.

Returns true if the roaring64_iterator returned true throughout (so that all data points were necessarily visited).

Iteration is ordered from the smallest to the largest elements.

◆ roaring64_bitmap_jaccard_index()

double roaring64_bitmap_jaccard_index ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the Jaccard index between two bitmaps. (Also known as the Tanimoto distance, or the Jaccard similarity coefficient)

The Jaccard index is undefined if both bitmaps are empty.

◆ roaring64_bitmap_maximum()

uint64_t roaring64_bitmap_maximum ( const roaring64_bitmap_t r)

Returns the largest value in the set, or 0 if empty.

◆ roaring64_bitmap_minimum()

uint64_t roaring64_bitmap_minimum ( const roaring64_bitmap_t r)

Returns the smallest value in the set, or UINT64_MAX if the set is empty.

◆ roaring64_bitmap_move_from_roaring32()

roaring64_bitmap_t* roaring64_bitmap_move_from_roaring32 ( roaring_bitmap_t r)

Create a new bitmap by moving containers from a 32 bit roaring bitmap.

After calling this function, the original bitmap will be empty, and the returned bitmap will contain all the values from the original bitmap.

◆ roaring64_bitmap_of_ptr()

roaring64_bitmap_t* roaring64_bitmap_of_ptr ( size_t  n_args,
const uint64_t *  vals 
)

Creates a new bitmap of a pointer to N 64-bit integers.

◆ roaring64_bitmap_or()

roaring64_bitmap_t* roaring64_bitmap_or ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the union between two bitmaps and returns new bitmap. The caller is responsible for free-ing the result.

◆ roaring64_bitmap_or_cardinality()

uint64_t roaring64_bitmap_or_cardinality ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the size of the union between two bitmaps.

◆ roaring64_bitmap_or_inplace()

void roaring64_bitmap_or_inplace ( roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

In-place version of roaring64_bitmap_or(), modifiesr1`.

◆ roaring64_bitmap_portable_deserialize_safe()

roaring64_bitmap_t* roaring64_bitmap_portable_deserialize_safe ( const char *  buf,
size_t  maxbytes 
)

Read a bitmap from a serialized buffer (reading up to maxbytes). In case of failure, NULL is returned.

This is meant to be compatible with other languages https://github.com/RoaringBitmap/RoaringFormatSpec#extension-for-64-bit-implementations

The function itself is safe in the sense that it will not cause buffer overflows: it will not read beyond the scope of the provided buffer (buf,maxbytes).

However, for correct operations, it is assumed that the bitmap read was once serialized from a valid bitmap (i.e., it follows the format specification). If you provided an incorrect input (garbage), then the bitmap read may not be in a valid state and following operations may not lead to sensible results. In particular, the serialized array containers need to be in sorted order, and the run containers should be in sorted non-overlapping order. This is is guaranteed to happen when serializing an existing bitmap, but not for random inputs.

If the source is untrusted, you should call roaring64_bitmap_internal_validate to check the validity of the bitmap prior to using it. Only after calling roaring64_bitmap_internal_validate is the bitmap considered safe for use.

We also recommend that you use checksums to check that serialized data corresponds to the serialized bitmap. The CRoaring library does not provide checksumming.

This function is endian-sensitive. If you have a big-endian system (e.g., a mainframe IBM s390x), the data format is going to be big-endian and not compatible with little-endian systems.

◆ roaring64_bitmap_portable_deserialize_size()

size_t roaring64_bitmap_portable_deserialize_size ( const char *  buf,
size_t  maxbytes 
)

Check how many bytes would be read (up to maxbytes) at this pointer if there is a valid bitmap, returns zero if there is no valid bitmap.

This is meant to be compatible with other languages https://github.com/RoaringBitmap/RoaringFormatSpec#extension-for-64-bit-implementations

◆ roaring64_bitmap_portable_serialize()

size_t roaring64_bitmap_portable_serialize ( const roaring64_bitmap_t r,
char *  buf 
)

Write a bitmap to a buffer. The output buffer should refer to at least roaring64_bitmap_portable_size_in_bytes(r) bytes of allocated memory.

Returns how many bytes were written, which should match roaring64_bitmap_portable_size_in_bytes(r).

This is meant to be compatible with other languages: https://github.com/RoaringBitmap/RoaringFormatSpec#extension-for-64-bit-implementations

This function is endian-sensitive. If you have a big-endian system (e.g., a mainframe IBM s390x), the data format is going to be big-endian and not compatible with little-endian systems.

When serializing data to a file, we recommend that you also use checksums so that, at deserialization, you can be confident that you are recovering the correct data.

◆ roaring64_bitmap_portable_size_in_bytes()

size_t roaring64_bitmap_portable_size_in_bytes ( const roaring64_bitmap_t r)

How many bytes are required to serialize this bitmap.

This is meant to be compatible with other languages: https://github.com/RoaringBitmap/RoaringFormatSpec#extension-for-64-bit-implementations

◆ roaring64_bitmap_range_cardinality()

uint64_t roaring64_bitmap_range_cardinality ( const roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Returns the number of elements in the range [min, max).

◆ roaring64_bitmap_range_closed_cardinality()

uint64_t roaring64_bitmap_range_closed_cardinality ( const roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Returns the number of elements in the range [min, max]

◆ roaring64_bitmap_rank()

uint64_t roaring64_bitmap_rank ( const roaring64_bitmap_t r,
uint64_t  val 
)

Returns the number of integers that are smaller or equal to x. Thus if x is the first element, this function will return 1. If x is smaller than the smallest element, this function will return 0.

The indexing convention differs between roaring64_bitmap_select and roaring64_bitmap_rank: roaring_bitmap64_select refers to the smallest value as having index 0, whereas roaring64_bitmap_rank returns 1 when ranking the smallest value.

◆ roaring64_bitmap_remove()

void roaring64_bitmap_remove ( roaring64_bitmap_t r,
uint64_t  val 
)

Removes a value from the bitmap if present.

◆ roaring64_bitmap_remove_bulk()

void roaring64_bitmap_remove_bulk ( roaring64_bitmap_t r,
roaring64_bulk_context_t context,
uint64_t  val 
)

Remove an item, using context from a previous insert for faster removal.

context will be used to store information between calls to make bulk operations faster. *context should be zero-initialized before the first call to this function.

Modifying the bitmap in any way (other than -bulk suffixed functions) will invalidate the stored context, calling this function with a non-zero context after doing any modification invokes undefined behavior.

In order to exploit this optimization, the caller should call this function with values with the same high 48 bits of the value consecutively.

◆ roaring64_bitmap_remove_checked()

bool roaring64_bitmap_remove_checked ( roaring64_bitmap_t r,
uint64_t  val 
)

Removes a value from the bitmap if present, returns true if the value was removed and false if the value was not present.

◆ roaring64_bitmap_remove_many()

void roaring64_bitmap_remove_many ( roaring64_bitmap_t r,
size_t  n_args,
const uint64_t *  vals 
)

Remove n_args values from vals, faster than repeatedly calling roaring64_bitmap_remove()

In order to exploit this optimization, the caller should attempt to keep values with the same high 48 bits of the value as consecutive elements in vals.

◆ roaring64_bitmap_remove_range()

void roaring64_bitmap_remove_range ( roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Remove all values in range [min, max).

◆ roaring64_bitmap_remove_range_closed()

void roaring64_bitmap_remove_range_closed ( roaring64_bitmap_t r,
uint64_t  min,
uint64_t  max 
)

Remove all values in range [min, max].

◆ roaring64_bitmap_run_optimize()

bool roaring64_bitmap_run_optimize ( roaring64_bitmap_t r)

Returns true if the result has at least one run container.

◆ roaring64_bitmap_select()

bool roaring64_bitmap_select ( const roaring64_bitmap_t r,
uint64_t  rank,
uint64_t *  element 
)

Selects the element at index 'rank' where the smallest element is at index 0. If the size of the bitmap is strictly greater than rank, then this function returns true and sets element to the element of given rank. Otherwise, it returns false.

◆ roaring64_bitmap_statistics()

void roaring64_bitmap_statistics ( const roaring64_bitmap_t r,
roaring64_statistics_t *  stat 
)

(For advanced users.) Collect statistics about the bitmap

◆ roaring64_bitmap_to_uint64_array()

void roaring64_bitmap_to_uint64_array ( const roaring64_bitmap_t r,
uint64_t *  out 
)

Convert the bitmap to a sorted array out.

Caller is responsible to ensure that there is enough memory allocated, e.g.

out = malloc(roaring64_bitmap_get_cardinality(bitmap) * sizeof(uint64_t));
uint64_t roaring64_bitmap_get_cardinality(const roaring64_bitmap_t *r)

◆ roaring64_bitmap_xor()

roaring64_bitmap_t* roaring64_bitmap_xor ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the symmetric difference (xor) between two bitmaps and returns a new bitmap. The caller is responsible for free-ing the result.

◆ roaring64_bitmap_xor_cardinality()

uint64_t roaring64_bitmap_xor_cardinality ( const roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

Computes the size of the symmetric difference (xor) between two bitmaps.

◆ roaring64_bitmap_xor_inplace()

void roaring64_bitmap_xor_inplace ( roaring64_bitmap_t r1,
const roaring64_bitmap_t r2 
)

In-place version of roaring64_bitmap_xor(), modifies r1. r1 and r2 are not allowed to be equal (that would result in an empty bitmap).

◆ roaring64_iterator_advance()

bool roaring64_iterator_advance ( roaring64_iterator_t it)

Advance the iterator. If there is a new value, then roaring64_iterator_has_value() returns true. Values are traversed in increasing order. For convenience, returns the result of roaring64_iterator_has_value().

Once this returns false, roaring64_iterator_advance should not be called on the iterator again. Calling roaring64_iterator_previous is allowed.

◆ roaring64_iterator_copy()

roaring64_iterator_t* roaring64_iterator_copy ( const roaring64_iterator_t it)

Creates a copy of the iterator. Caller is responsible for calling roaring64_iterator_free() on the resulting iterator.

◆ roaring64_iterator_create()

roaring64_iterator_t* roaring64_iterator_create ( const roaring64_bitmap_t r)

Create an iterator object that can be used to iterate through the values. Caller is responsible for calling roaring64_iterator_free().

The iterator is initialized. If there is a value, then this iterator points to the first value and roaring64_iterator_has_value() returns true. The value can be retrieved with roaring64_iterator_value().

◆ roaring64_iterator_create_last()

roaring64_iterator_t* roaring64_iterator_create_last ( const roaring64_bitmap_t r)

Create an iterator object that can be used to iterate through the values. Caller is responsible for calling roaring64_iterator_free().

The iterator is initialized. If there is a value, then this iterator points to the last value and roaring64_iterator_has_value() returns true. The value can be retrieved with roaring64_iterator_value().

◆ roaring64_iterator_free()

void roaring64_iterator_free ( roaring64_iterator_t it)

Free the iterator.

◆ roaring64_iterator_has_value()

bool roaring64_iterator_has_value ( const roaring64_iterator_t it)

Returns true if the iterator currently points to a value. If so, calling roaring64_iterator_value() returns the value.

◆ roaring64_iterator_move_equalorlarger()

bool roaring64_iterator_move_equalorlarger ( roaring64_iterator_t it,
uint64_t  val 
)

Move the iterator to the first value greater than or equal to val, if it exists at or after the current position of the iterator. If there is a new value, then roaring64_iterator_has_value() returns true. Values are traversed in increasing order. For convenience, returns the result of roaring64_iterator_has_value().

◆ roaring64_iterator_previous()

bool roaring64_iterator_previous ( roaring64_iterator_t it)

Decrement the iterator. If there is a new value, then roaring64_iterator_has_value() returns true. Values are traversed in decreasing order. For convenience, returns the result of roaring64_iterator_has_value().

Once this returns false, roaring64_iterator_previous should not be called on the iterator again. Calling roaring64_iterator_advance is allowed.

◆ roaring64_iterator_read()

uint64_t roaring64_iterator_read ( roaring64_iterator_t it,
uint64_t *  buf,
uint64_t  count 
)

Reads up to count values from the iterator into the given buf. Returns the number of elements read. The number of elements read can be smaller than count, which means that there are no more elements in the bitmap.

This function can be used together with other iterator functions.

◆ roaring64_iterator_reinit()

void roaring64_iterator_reinit ( const roaring64_bitmap_t r,
roaring64_iterator_t it 
)

Re-initializes an existing iterator. Functionally the same as roaring64_iterator_create without a allocation.

◆ roaring64_iterator_reinit_last()

void roaring64_iterator_reinit_last ( const roaring64_bitmap_t r,
roaring64_iterator_t it 
)

Re-initializes an existing iterator. Functionally the same as roaring64_iterator_create_last without a allocation.

◆ roaring64_iterator_value()

uint64_t roaring64_iterator_value ( const roaring64_iterator_t it)

Returns the value the iterator currently points to. Should only be called if roaring64_iterator_has_value() returns true.