CRoaring  4.2.1
Roaring bitmaps in C (and C++)
roaring::Roaring Class Reference

#include <roaring.hh>

Public Types

typedef RoaringSetBitBiDirectionalIterator const_iterator
 
typedef RoaringSetBitBiDirectionalIterator const_bidirectional_iterator
 

Public Member Functions

 Roaring ()
 
 Roaring (size_t n, const uint32_t *data)
 
 Roaring (std::initializer_list< uint32_t > l)
 
 Roaring (roaring_bitmap_t *s) noexcept
 
 Roaring (const Roaring &r)
 
 Roaring (Roaring &&r) noexcept
 
Roaringoperator= (const Roaring &r)
 
Roaringoperator= (Roaring &&r) noexcept
 
Roaringoperator= (std::initializer_list< uint32_t > l)
 
void add (uint32_t x) noexcept
 
bool addChecked (uint32_t x) noexcept
 
void addRange (const uint64_t min, const uint64_t max) noexcept
 
void addRangeClosed (const uint32_t min, const uint32_t max) noexcept
 
void addMany (size_t n_args, const uint32_t *vals) noexcept
 
void addBulk (BulkContext &context, uint32_t x) noexcept
 
bool containsBulk (BulkContext &context, uint32_t x) const noexcept
 
void remove (uint32_t x) noexcept
 
bool removeChecked (uint32_t x) noexcept
 
void removeRange (uint64_t min, uint64_t max) noexcept
 
void removeRangeClosed (uint32_t min, uint32_t max) noexcept
 
void clear ()
 
uint32_t maximum () const noexcept
 
uint32_t minimum () const noexcept
 
bool contains (uint32_t x) const noexcept
 
bool containsRange (const uint64_t x, const uint64_t y) const noexcept
 
bool containsRangeClosed (const uint32_t x, const uint32_t y) const noexcept
 
Roaringoperator&= (const Roaring &r) noexcept
 
Roaringoperator-= (const Roaring &r) noexcept
 
Roaringoperator|= (const Roaring &r) noexcept
 
Roaringoperator^= (const Roaring &r) noexcept
 
void swap (Roaring &r) noexcept
 
uint64_t cardinality () const noexcept
 
bool isEmpty () const noexcept
 
bool isFull () const noexcept
 
bool isSubset (const Roaring &r) const noexcept
 
bool isStrictSubset (const Roaring &r) const noexcept
 
void toUint32Array (uint32_t *ans) const noexcept
 
void rangeUint32Array (uint32_t *ans, size_t offset, size_t limit) const noexcept
 
bool operator== (const Roaring &r) const noexcept
 
void flip (uint64_t range_start, uint64_t range_end) noexcept
 
void flipClosed (uint32_t range_start, uint32_t range_end) noexcept
 
bool removeRunCompression () noexcept
 
bool runOptimize () noexcept
 
size_t shrinkToFit () noexcept
 
void iterate (api::roaring_iterator iterator, void *ptr) const
 
bool select (uint32_t rnk, uint32_t *element) const noexcept
 
uint64_t and_cardinality (const Roaring &r) const noexcept
 
bool intersect (const Roaring &r) const noexcept
 
double jaccard_index (const Roaring &r) const noexcept
 
uint64_t or_cardinality (const Roaring &r) const noexcept
 
uint64_t andnot_cardinality (const Roaring &r) const noexcept
 
uint64_t xor_cardinality (const Roaring &r) const noexcept
 
uint64_t rank (uint32_t x) const noexcept
 
void rank_many (const uint32_t *begin, const uint32_t *end, uint64_t *ans) const noexcept
 
int64_t getIndex (uint32_t x) const noexcept
 
size_t write (char *buf, bool portable=true) const noexcept
 
size_t getSizeInBytes (bool portable=true) const noexcept
 
void writeFrozen (char *buf) const noexcept
 
size_t getFrozenSizeInBytes () const noexcept
 
Roaring operator& (const Roaring &o) const
 
Roaring operator- (const Roaring &o) const
 
Roaring operator| (const Roaring &o) const
 
Roaring operator^ (const Roaring &o) const
 
void setCopyOnWrite (bool val) noexcept
 
void printf () const noexcept
 
std::string toString () const noexcept
 
bool getCopyOnWrite () const noexcept
 
 ~Roaring ()
 
const_iterator begin () const
 
const_iteratorend () const
 

Static Public Member Functions

static Roaring bitmapOf (size_t n,...)
 
static Roaring bitmapOfList (std::initializer_list< uint32_t > l)
 
static Roaring read (const char *buf, bool portable=true)
 
static Roaring readSafe (const char *buf, size_t maxbytes)
 
static const Roaring frozenView (const char *buf, size_t length)
 
static const Roaring portableDeserializeFrozen (const char *buf)
 
static Roaring fastunion (size_t n, const Roaring **inputs)
 

Public Attributes

roaring_bitmap_t roaring
 

Friends

class RoaringSetBitBiDirectionalIterator
 

Detailed Description

Definition at line 70 of file roaring.hh.

Member Typedef Documentation

◆ const_bidirectional_iterator

◆ const_iterator

Constructor & Destructor Documentation

◆ Roaring() [1/6]

roaring::Roaring::Roaring ( )
inline

Create an empty bitmap in the existing memory for the class. The bitmap will be in the "clear" state with no auxiliary allocations.

Definition at line 78 of file roaring.hh.

References roaring_bitmap_init_cleared().

◆ Roaring() [2/6]

roaring::Roaring::Roaring ( size_t  n,
const uint32_t *  data 
)
inline

Construct a bitmap from a list of 32-bit integer values.

Definition at line 87 of file roaring.hh.

References roaring_bitmap_add_many().

◆ Roaring() [3/6]

roaring::Roaring::Roaring ( std::initializer_list< uint32_t >  l)
inline

Construct a bitmap from an initializer list.

Definition at line 94 of file roaring.hh.

◆ Roaring() [4/6]

roaring::Roaring::Roaring ( roaring_bitmap_t *  s)
inlineexplicitnoexcept

Construct a roaring object by taking control of a malloc()'d C struct.

Passing a NULL pointer is unsafe. The pointer to the C struct will be invalid after the call.

Definition at line 104 of file roaring.hh.

◆ Roaring() [5/6]

roaring::Roaring::Roaring ( const Roaring r)
inline

Copy constructor. It may throw std::runtime_error if there is insufficient memory.

Definition at line 112 of file roaring.hh.

References roaring, roaring_bitmap_get_copy_on_write(), roaring_bitmap_overwrite(), roaring_bitmap_set_copy_on_write(), and ROARING_TERMINATE.

◆ Roaring() [6/6]

roaring::Roaring::Roaring ( Roaring &&  r)
inlinenoexcept

Move constructor. The moved-from object remains valid but empty, i.e. it behaves as though it was just freshly constructed.

Definition at line 124 of file roaring.hh.

References roaring_bitmap_init_cleared().

◆ ~Roaring()

roaring::Roaring::~Roaring ( )
inline

Destructor. By contract, calling roaring_bitmap_clear() is enough to release all auxiliary memory used by the structure.

Definition at line 878 of file roaring.hh.

References roaring_bitmap_clear(), and roaring_bitmap_free().

Member Function Documentation

◆ add()

void roaring::Roaring::add ( uint32_t  x)
inlinenoexcept

Add value x

Definition at line 200 of file roaring.hh.

References roaring_bitmap_add().

Referenced by roaring::Roaring64Map::add(), and bitmapOf().

◆ addBulk()

void roaring::Roaring::addBulk ( BulkContext context,
uint32_t  x 
)
inlinenoexcept

Add value val, using context from a previous insert for speed optimization.

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

Definition at line 240 of file roaring.hh.

References roaring_bitmap_add_bulk().

Referenced by roaring::Roaring64Map::addMany().

◆ addChecked()

bool roaring::Roaring::addChecked ( uint32_t  x)
inlinenoexcept

Add value x Returns true if a new value was added, false if the value was already existing.

Definition at line 207 of file roaring.hh.

References roaring_bitmap_add_checked().

Referenced by roaring::Roaring64Map::addChecked().

◆ addMany()

void roaring::Roaring::addMany ( size_t  n_args,
const uint32_t *  vals 
)
inlinenoexcept

Add value n_args from pointer vals

Definition at line 228 of file roaring.hh.

References roaring_bitmap_add_many().

Referenced by roaring::Roaring64Map::addMany(), and bitmapOfList().

◆ addRange()

void roaring::Roaring::addRange ( const uint64_t  min,
const uint64_t  max 
)
inlinenoexcept

Add all values in range [min, max)

Definition at line 214 of file roaring.hh.

References roaring_bitmap_add_range().

◆ addRangeClosed()

void roaring::Roaring::addRangeClosed ( const uint32_t  min,
const uint32_t  max 
)
inlinenoexcept

Add all values in range [min, max]

Definition at line 221 of file roaring.hh.

References roaring_bitmap_add_range_closed().

Referenced by roaring::Roaring64Map::addRangeClosed().

◆ and_cardinality()

uint64_t roaring::Roaring::and_cardinality ( const Roaring r) const
inlinenoexcept

Computes the size of the intersection between two bitmaps.

Definition at line 507 of file roaring.hh.

References roaring_bitmap_and_cardinality().

◆ andnot_cardinality()

uint64_t roaring::Roaring::andnot_cardinality ( const Roaring r) const
inlinenoexcept

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

Definition at line 539 of file roaring.hh.

References roaring_bitmap_andnot_cardinality().

◆ begin()

RoaringSetBitBiDirectionalIterator roaring::Roaring::begin ( ) const
inline

Returns an iterator that can be used to access the position of the set bits. The running time complexity of a full scan is proportional to the number of set bits: be aware that if you have long strings of 1s, this can be very inefficient.

It can be much faster to use the toArray method if you want to retrieve the set bits.

Definition at line 1020 of file roaring.hh.

◆ bitmapOf()

static Roaring roaring::Roaring::bitmapOf ( size_t  n,
  ... 
)
inlinestatic

Construct a bitmap from a list of uint32_t values.

Definition at line 138 of file roaring.hh.

References add().

◆ bitmapOfList()

static Roaring roaring::Roaring::bitmapOfList ( std::initializer_list< uint32_t >  l)
inlinestatic

Construct a bitmap from a list of uint32_t values. E.g., bitmapOfList({1,2,3}).

Definition at line 191 of file roaring.hh.

References addMany().

◆ cardinality()

uint64_t roaring::Roaring::cardinality ( ) const
inlinenoexcept

Get the cardinality of the bitmap (number of elements).

Definition at line 378 of file roaring.hh.

References roaring_bitmap_get_cardinality().

◆ clear()

void roaring::Roaring::clear ( )
inline

Clears the bitmap.

Definition at line 290 of file roaring.hh.

References roaring_bitmap_clear().

◆ contains()

bool roaring::Roaring::contains ( uint32_t  x) const
inlinenoexcept

Check if value x is present

Definition at line 309 of file roaring.hh.

References roaring_bitmap_contains().

◆ containsBulk()

bool roaring::Roaring::containsBulk ( BulkContext context,
uint32_t  x 
) const
inlinenoexcept

Check if item x is present, using context from a previous insert or search for speed optimization.

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

Definition at line 252 of file roaring.hh.

References roaring_bitmap_contains_bulk().

◆ containsRange()

bool roaring::Roaring::containsRange ( const uint64_t  x,
const uint64_t  y 
) const
inlinenoexcept

Check if all values from x (included) to y (excluded) are present

Definition at line 316 of file roaring.hh.

References roaring_bitmap_contains_range().

◆ containsRangeClosed()

bool roaring::Roaring::containsRangeClosed ( const uint32_t  x,
const uint32_t  y 
) const
inlinenoexcept

Definition at line 320 of file roaring.hh.

References roaring_bitmap_contains_range_closed().

◆ end()

RoaringSetBitBiDirectionalIterator & roaring::Roaring::end ( ) const
inline

A bogus iterator that can be used together with begin() for constructions such as for (auto i = b.begin(); * i!=b.end(); ++i) {}

Definition at line 1024 of file roaring.hh.

◆ fastunion()

static Roaring roaring::Roaring::fastunion ( size_t  n,
const Roaring **  inputs 
)
inlinestatic

Computes the logical or (union) between "n" bitmaps (referenced by a pointer). This function may throw std::runtime_error.

Definition at line 856 of file roaring.hh.

References roaring_bitmap_or_many(), and ROARING_TERMINATE.

◆ flip()

void roaring::Roaring::flip ( uint64_t  range_start,
uint64_t  range_end 
)
inlinenoexcept

Compute the negation of the roaring bitmap within the half-open interval [range_start, range_end). Areas outside the interval are unchanged.

Definition at line 440 of file roaring.hh.

References roaring_bitmap_flip_inplace().

◆ flipClosed()

void roaring::Roaring::flipClosed ( uint32_t  range_start,
uint32_t  range_end 
)
inlinenoexcept

Compute the negation of the roaring bitmap within the closed interval [range_start, range_end]. Areas outside the interval are unchanged.

Definition at line 448 of file roaring.hh.

References roaring_bitmap_flip_inplace_closed().

◆ frozenView()

static const Roaring roaring::Roaring::frozenView ( const char *  buf,
size_t  length 
)
inlinestatic

For advanced users. This function may throw std::runtime_error.

Definition at line 709 of file roaring.hh.

References roaring, roaring_bitmap_frozen_view(), and ROARING_TERMINATE.

Referenced by roaring::Roaring64Map::frozenView().

◆ getCopyOnWrite()

bool roaring::Roaring::getCopyOnWrite ( ) const
inlinenoexcept

Whether or not copy and write is active.

Definition at line 847 of file roaring.hh.

References roaring_bitmap_get_copy_on_write().

◆ getFrozenSizeInBytes()

size_t roaring::Roaring::getFrozenSizeInBytes ( ) const
inlinenoexcept

For advanced users.

Definition at line 745 of file roaring.hh.

References roaring_bitmap_frozen_size_in_bytes().

◆ getIndex()

int64_t roaring::Roaring::getIndex ( uint32_t  x) const
inlinenoexcept

Returns the index of x in the set, index start from 0. If the set doesn't contain x , this function will return -1. The difference with rank function is that this function will return -1 when x isn't in the set, but the rank function will return a non-negative number.

Definition at line 580 of file roaring.hh.

References roaring_bitmap_get_index().

◆ getSizeInBytes()

size_t roaring::Roaring::getSizeInBytes ( bool  portable = true) const
inlinenoexcept

How many bytes are required to serialize this bitmap (meant to be compatible with Java and Go versions)

Setting the portable flag to false enable a custom format that can save space compared to the portable format (e.g., for very sparse bitmaps).

Definition at line 697 of file roaring.hh.

References roaring_bitmap_portable_size_in_bytes(), and roaring_bitmap_size_in_bytes().

Referenced by roaring::Roaring64Map::portableDeserializeFrozen(), roaring::Roaring64Map::read(), and roaring::Roaring64Map::readSafe().

◆ intersect()

bool roaring::Roaring::intersect ( const Roaring r) const
inlinenoexcept

Check whether the two bitmaps intersect.

Definition at line 514 of file roaring.hh.

References roaring_bitmap_intersect().

◆ isEmpty()

bool roaring::Roaring::isEmpty ( ) const
inlinenoexcept

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

Definition at line 385 of file roaring.hh.

References roaring_bitmap_is_empty().

◆ isFull()

bool roaring::Roaring::isFull ( ) const
inlinenoexcept

Returns true if the bitmap is full (cardinality is uint32_t max + 1). we put std::numeric_limits<>::max/min in parentheses to avoid a clash with the Windows.h header under Windows.

Definition at line 394 of file roaring.hh.

References roaring_bitmap_get_cardinality().

◆ isStrictSubset()

bool roaring::Roaring::isStrictSubset ( const Roaring r) const
inlinenoexcept

Returns true if the bitmap is strict subset of the other.

Definition at line 409 of file roaring.hh.

References roaring_bitmap_is_strict_subset().

◆ isSubset()

bool roaring::Roaring::isSubset ( const Roaring r) const
inlinenoexcept

Returns true if the bitmap is subset of the other.

Definition at line 402 of file roaring.hh.

References roaring_bitmap_is_subset().

◆ iterate()

void roaring::Roaring::iterate ( api::roaring_iterator  iterator,
void *  ptr 
) const
inline

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_iterator is simply a pointer to a function that returns bool (true means that the iteration should continue while false means that it should stop), and takes (uint32_t,void*) as inputs.

Definition at line 488 of file roaring.hh.

References roaring_iterate().

◆ jaccard_index()

double roaring::Roaring::jaccard_index ( const Roaring r) const
inlinenoexcept

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.

Definition at line 525 of file roaring.hh.

References roaring_bitmap_jaccard_index().

◆ maximum()

uint32_t roaring::Roaring::maximum ( ) const
inlinenoexcept

Return the largest value (if not empty)

Definition at line 295 of file roaring.hh.

References roaring_bitmap_maximum().

◆ minimum()

uint32_t roaring::Roaring::minimum ( ) const
inlinenoexcept

Return the smallest value (if not empty)

Definition at line 302 of file roaring.hh.

References roaring_bitmap_minimum().

◆ operator&()

Roaring roaring::Roaring::operator& ( const Roaring o) const
inline

Computes the intersection between two bitmaps and returns new bitmap. The current bitmap and the provided bitmap are unchanged.

Performance hint: if you are computing the intersection between several bitmaps, two-by-two, it is best to start with the smallest bitmap. Consider also using the operator &= to avoid needlessly creating many temporary bitmaps. This function may throw std::runtime_error.

Definition at line 759 of file roaring.hh.

References roaring::BulkContext::Roaring, roaring, roaring_bitmap_and(), and ROARING_TERMINATE.

◆ operator&=()

Roaring& roaring::Roaring::operator&= ( const Roaring r)
inlinenoexcept

Compute the intersection between the current bitmap and the provided bitmap, writing the result in the current bitmap. The provided bitmap is not modified.

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

Definition at line 333 of file roaring.hh.

References roaring_bitmap_and_inplace().

◆ operator-()

Roaring roaring::Roaring::operator- ( const Roaring o) const
inline

Computes the difference between two bitmaps and returns new bitmap. The current bitmap and the provided bitmap are unchanged. This function may throw std::runtime_error.

Definition at line 772 of file roaring.hh.

References roaring::BulkContext::Roaring, roaring, roaring_bitmap_andnot(), and ROARING_TERMINATE.

◆ operator-=()

Roaring& roaring::Roaring::operator-= ( const Roaring r)
inlinenoexcept

Compute the difference between the current bitmap and the provided bitmap, writing the result in the current bitmap. The provided bitmap is not modified.

Definition at line 343 of file roaring.hh.

References roaring_bitmap_andnot_inplace().

◆ operator=() [1/3]

Roaring& roaring::Roaring::operator= ( const Roaring r)
inline

Copies the content of the provided bitmap, and discard the current content. It may throw std::runtime_error if there is insufficient memory.

Definition at line 154 of file roaring.hh.

References roaring, roaring_bitmap_get_copy_on_write(), roaring_bitmap_overwrite(), roaring_bitmap_set_copy_on_write(), and ROARING_TERMINATE.

◆ operator=() [2/3]

Roaring& roaring::Roaring::operator= ( Roaring &&  r)
inlinenoexcept

Moves the content of the provided bitmap, and discard the current content.

Definition at line 167 of file roaring.hh.

References roaring_bitmap_clear(), and roaring_bitmap_init_cleared().

◆ operator=() [3/3]

Roaring& roaring::Roaring::operator= ( std::initializer_list< uint32_t >  l)
inline

Assignment from an initializer list.

Definition at line 181 of file roaring.hh.

References roaring::BulkContext::Roaring.

◆ operator==()

bool roaring::Roaring::operator== ( const Roaring r) const
inlinenoexcept

Return true if the two bitmaps contain the same elements.

Definition at line 432 of file roaring.hh.

References roaring_bitmap_equals().

◆ operator^()

Roaring roaring::Roaring::operator^ ( const Roaring o) const
inline

Computes the symmetric union between two bitmaps and returns new bitmap. The current bitmap and the provided bitmap are unchanged. This function may throw std::runtime_error.

Definition at line 798 of file roaring.hh.

References roaring::BulkContext::Roaring, roaring, roaring_bitmap_xor(), and ROARING_TERMINATE.

◆ operator^=()

Roaring& roaring::Roaring::operator^= ( const Roaring r)
inlinenoexcept

Compute the symmetric union between the current bitmap and the provided bitmap, writing the result in the current bitmap. The provided bitmap is not modified.

Definition at line 365 of file roaring.hh.

References roaring_bitmap_xor_inplace().

◆ operator|()

Roaring roaring::Roaring::operator| ( const Roaring o) const
inline

Computes the union between two bitmaps and returns new bitmap. The current bitmap and the provided bitmap are unchanged. This function may throw std::runtime_error.

Definition at line 785 of file roaring.hh.

References roaring::BulkContext::Roaring, roaring, roaring_bitmap_or(), and ROARING_TERMINATE.

◆ operator|=()

Roaring& roaring::Roaring::operator|= ( const Roaring r)
inlinenoexcept

Compute the union between the current bitmap and the provided bitmap, writing the result in the current bitmap. The provided bitmap is not modified.

See also the fastunion function to aggregate many bitmaps more quickly.

Definition at line 355 of file roaring.hh.

References roaring_bitmap_or_inplace().

◆ or_cardinality()

uint64_t roaring::Roaring::or_cardinality ( const Roaring r) const
inlinenoexcept

Computes the size of the union between two bitmaps.

Definition at line 532 of file roaring.hh.

References roaring_bitmap_or_cardinality().

◆ portableDeserializeFrozen()

static const Roaring roaring::Roaring::portableDeserializeFrozen ( const char *  buf)
inlinestatic

For advanced users; see roaring_bitmap_portable_deserialize_frozen. This function may throw std::runtime_error.

Definition at line 724 of file roaring.hh.

References roaring, roaring_bitmap_portable_deserialize_frozen(), and ROARING_TERMINATE.

Referenced by roaring::Roaring64Map::portableDeserializeFrozen().

◆ printf()

void roaring::Roaring::printf ( ) const
inlinenoexcept

Print the content of the bitmap

Definition at line 816 of file roaring.hh.

References roaring_bitmap_printf().

◆ rangeUint32Array()

void roaring::Roaring::rangeUint32Array ( uint32_t *  ans,
size_t  offset,
size_t  limit 
) const
inlinenoexcept

To int array with pagination

Definition at line 424 of file roaring.hh.

References roaring_bitmap_range_uint32_array().

◆ rank()

uint64_t roaring::Roaring::rank ( uint32_t  x) const
inlinenoexcept

Returns the number of integers that are smaller or equal to x. Thus the rank of the smallest element is one. If x is smaller than the smallest element, this function will return 0. The rank and select functions differ in convention: this function returns 1 when ranking the smallest value, but the select function returns the smallest value when using index 0.

Definition at line 559 of file roaring.hh.

References roaring_bitmap_rank().

◆ rank_many()

void roaring::Roaring::rank_many ( const uint32_t *  begin,
const uint32_t *  end,
uint64_t *  ans 
) const
inlinenoexcept

Get rank() values in bulk. The values in [begin .. end) must be in Ascending order. possible implementation: for(auto* iter = begin; iter != end; ++iter) *(ans++) = rank(*iter);

Definition at line 568 of file roaring.hh.

References roaring_bitmap_rank_many().

◆ read()

static Roaring roaring::Roaring::read ( const char *  buf,
bool  portable = true 
)
inlinestatic

Read a bitmap from a serialized version. This is meant to be compatible with the Java and Go versions.

Setting the portable flag to false enable a custom format that can save space compared to the portable format (e.g., for very sparse bitmaps).

This function is unsafe in the sense that if you provide bad data, many, many bytes could be read. See also readSafe.

The function may throw std::runtime_error if a bitmap could not be read. Not that even if it does not throw, the bitmap could still be unusable if the loaded data does not match the portable Roaring specification: you should ensure that the data you load come from a serialized bitmap.

Definition at line 647 of file roaring.hh.

References roaring::BulkContext::Roaring, roaring_bitmap_deserialize(), roaring_bitmap_portable_deserialize(), and ROARING_TERMINATE.

Referenced by roaring::Roaring64Map::read().

◆ readSafe()

static Roaring roaring::Roaring::readSafe ( const char *  buf,
size_t  maxbytes 
)
inlinestatic

Read a bitmap from a serialized version, reading no more than maxbytes bytes. This is meant to be compatible with the Java and Go versions. The function itself is safe in the sense that it will not cause buffer overflows. However, for correct operations, it is assumed that the bitmap read was once serialized from a valid bitmap. 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. It is your responsability to ensure that the input bytes follow the format specification if you want a usable bitmap: https://github.com/RoaringBitmap/RoaringFormatSpec 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. Note that this function assumes that your bitmap was serialized in portable mode (which is the default with the 'write' method).

The function may throw std::runtime_error if a bitmap could not be read. Not that even if it does not throw, the bitmap could still be unusable if the loaded data does not match the portable Roaring specification: you should ensure that the data you load come from a serialized bitmap.

Definition at line 680 of file roaring.hh.

References roaring::BulkContext::Roaring, roaring_bitmap_portable_deserialize_safe(), and ROARING_TERMINATE.

Referenced by roaring::Roaring64Map::readSafe().

◆ remove()

void roaring::Roaring::remove ( uint32_t  x)
inlinenoexcept

Remove value x

Definition at line 260 of file roaring.hh.

References roaring_bitmap_remove().

◆ removeChecked()

bool roaring::Roaring::removeChecked ( uint32_t  x)
inlinenoexcept

Remove value x Returns true if a new value was removed, false if the value was not existing.

Definition at line 269 of file roaring.hh.

References roaring_bitmap_remove_checked().

◆ removeRange()

void roaring::Roaring::removeRange ( uint64_t  min,
uint64_t  max 
)
inlinenoexcept

Remove all values in range [min, max)

Definition at line 276 of file roaring.hh.

References roaring_bitmap_remove_range().

◆ removeRangeClosed()

void roaring::Roaring::removeRangeClosed ( uint32_t  min,
uint32_t  max 
)
inlinenoexcept

Remove all values in range [min, max]

Definition at line 283 of file roaring.hh.

References roaring_bitmap_remove_range_closed().

◆ removeRunCompression()

bool roaring::Roaring::removeRunCompression ( )
inlinenoexcept

Remove run-length encoding even when it is more space efficient. Return whether a change was applied.

Definition at line 457 of file roaring.hh.

References roaring_bitmap_remove_run_compression().

◆ runOptimize()

bool roaring::Roaring::runOptimize ( )
inlinenoexcept

Convert array and bitmap containers to run containers when it is more efficient; also convert from run containers when more space efficient. Returns true if the result has at least one run container. Additional savings might be possible by calling shrinkToFit().

Definition at line 467 of file roaring.hh.

References roaring_bitmap_run_optimize().

◆ select()

bool roaring::Roaring::select ( uint32_t  rnk,
uint32_t *  element 
) const
inlinenoexcept

Selects the value at index rnk in the bitmap, where the smallest value is at index 0.

If the size of the roaring bitmap is strictly greater than rank, then this function returns true and sets element to the element of given rank. Otherwise, it returns false.

Definition at line 500 of file roaring.hh.

References roaring_bitmap_select().

◆ setCopyOnWrite()

void roaring::Roaring::setCopyOnWrite ( bool  val)
inlinenoexcept

Whether or not we apply copy and write.

Definition at line 809 of file roaring.hh.

References roaring_bitmap_set_copy_on_write().

◆ shrinkToFit()

size_t roaring::Roaring::shrinkToFit ( )
inlinenoexcept

If needed, reallocate memory to shrink the memory usage. Returns the number of bytes saved.

Definition at line 475 of file roaring.hh.

References roaring_bitmap_shrink_to_fit().

◆ swap()

void roaring::Roaring::swap ( Roaring r)
inlinenoexcept

Exchange the content of this bitmap with another.

Definition at line 373 of file roaring.hh.

◆ toString()

std::string roaring::Roaring::toString ( ) const
inlinenoexcept

Print the content of the bitmap into a string

Definition at line 821 of file roaring.hh.

◆ toUint32Array()

void roaring::Roaring::toUint32Array ( uint32_t *  ans) const
inlinenoexcept

Convert the bitmap to an array. Write the output to "ans", caller is responsible to ensure that there is enough memory allocated (e.g., ans = new uint32[mybitmap.cardinality()];)

Definition at line 418 of file roaring.hh.

References roaring_bitmap_to_uint32_array().

◆ write()

size_t roaring::Roaring::write ( char *  buf,
bool  portable = true 
) const
inlinenoexcept

Write a bitmap to a char buffer. This is meant to be compatible with the Java and Go versions. Returns how many bytes were written which should be getSizeInBytes().

Setting the portable flag to false enable a custom format that can save space compared to the portable format (e.g., for very sparse bitmaps).

Boost users can serialize bitmaps in this manner:

  BOOST_SERIALIZATION_SPLIT_FREE(Roaring)
  namespace boost {
  namespace serialization {

  template <class Archive>
  void save(Archive& ar, const Roaring& bitmask,
     const unsigned int version) {
    std::size_t expected_size_in_bytes = bitmask.getSizeInBytes();
    std::vector<char> buffer(expected_size_in_bytes);
    std::size_t       size_in_bytes = bitmask.write(buffer.data());

    ar& size_in_bytes;
    ar& boost::serialization::make_binary_object(buffer.data(),
        size_in_bytes);
 }
 template <class Archive>
 void load(Archive& ar, Roaring& bitmask,
     const unsigned int version) {
    std::size_t size_in_bytes = 0;
    ar& size_in_bytes;
    std::vector<char> buffer(size_in_bytes);
    ar&  boost::serialization::make_binary_object(buffer.data(),
       size_in_bytes);
    bitmask = Roaring::readSafe(buffer.data(), size_in_bytes);
 }
 }  // namespace serialization
 }  // namespace boost

Definition at line 623 of file roaring.hh.

References roaring_bitmap_portable_serialize(), and roaring_bitmap_serialize().

◆ writeFrozen()

void roaring::Roaring::writeFrozen ( char *  buf) const
inlinenoexcept

For advanced users.

Definition at line 738 of file roaring.hh.

References roaring_bitmap_frozen_serialize().

◆ xor_cardinality()

uint64_t roaring::Roaring::xor_cardinality ( const Roaring r) const
inlinenoexcept

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

Definition at line 547 of file roaring.hh.

References roaring_bitmap_xor_cardinality().

Friends And Related Function Documentation

◆ RoaringSetBitBiDirectionalIterator

Definition at line 895 of file roaring.hh.

Member Data Documentation

◆ roaring


The documentation for this class was generated from the following file: