CRoaring
4.2.1
Roaring bitmaps in C (and C++)
|
#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 | |
Roaring & | operator= (const Roaring &r) |
Roaring & | operator= (Roaring &&r) noexcept |
Roaring & | operator= (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 |
Roaring & | operator&= (const Roaring &r) noexcept |
Roaring & | operator-= (const Roaring &r) noexcept |
Roaring & | operator|= (const Roaring &r) noexcept |
Roaring & | operator^= (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_iterator & | end () 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 |
Definition at line 70 of file roaring.hh.
Definition at line 897 of file roaring.hh.
Definition at line 896 of file roaring.hh.
|
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().
|
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().
|
inline |
Construct a bitmap from an initializer list.
Definition at line 94 of file roaring.hh.
|
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.
|
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.
|
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().
|
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().
|
inlinenoexcept |
Add value x
Definition at line 200 of file roaring.hh.
References roaring_bitmap_add().
Referenced by roaring::Roaring64Map::add(), and bitmapOf().
|
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().
|
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().
|
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().
|
inlinenoexcept |
Add all values in range [min, max)
Definition at line 214 of file roaring.hh.
References roaring_bitmap_add_range().
|
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().
|
inlinenoexcept |
Computes the size of the intersection between two bitmaps.
Definition at line 507 of file roaring.hh.
References roaring_bitmap_and_cardinality().
|
inlinenoexcept |
Computes the size of the difference (andnot) between two bitmaps.
Definition at line 539 of file roaring.hh.
References roaring_bitmap_andnot_cardinality().
|
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.
|
inlinestatic |
Construct a bitmap from a list of uint32_t values.
Definition at line 138 of file roaring.hh.
References add().
|
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().
|
inlinenoexcept |
Get the cardinality of the bitmap (number of elements).
Definition at line 378 of file roaring.hh.
References roaring_bitmap_get_cardinality().
|
inline |
|
inlinenoexcept |
Check if value x is present
Definition at line 309 of file roaring.hh.
References roaring_bitmap_contains().
|
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().
|
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().
|
inlinenoexcept |
Definition at line 320 of file roaring.hh.
References roaring_bitmap_contains_range_closed().
|
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.
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.
|
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().
|
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().
|
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().
|
inlinenoexcept |
Whether or not copy and write is active.
Definition at line 847 of file roaring.hh.
References roaring_bitmap_get_copy_on_write().
|
inlinenoexcept |
For advanced users.
Definition at line 745 of file roaring.hh.
References roaring_bitmap_frozen_size_in_bytes().
|
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().
|
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().
|
inlinenoexcept |
Check whether the two bitmaps intersect.
Definition at line 514 of file roaring.hh.
References roaring_bitmap_intersect().
|
inlinenoexcept |
Returns true if the bitmap is empty (cardinality is zero).
Definition at line 385 of file roaring.hh.
References roaring_bitmap_is_empty().
|
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().
|
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().
|
inlinenoexcept |
Returns true if the bitmap is subset of the other.
Definition at line 402 of file roaring.hh.
References roaring_bitmap_is_subset().
|
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().
|
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().
|
inlinenoexcept |
Return the largest value (if not empty)
Definition at line 295 of file roaring.hh.
References roaring_bitmap_maximum().
|
inlinenoexcept |
Return the smallest value (if not empty)
Definition at line 302 of file roaring.hh.
References roaring_bitmap_minimum().
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.
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().
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.
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().
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.
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().
|
inline |
Assignment from an initializer list.
Definition at line 181 of file roaring.hh.
References roaring::BulkContext::Roaring.
|
inlinenoexcept |
Return true if the two bitmaps contain the same elements.
Definition at line 432 of file roaring.hh.
References roaring_bitmap_equals().
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.
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().
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.
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().
|
inlinenoexcept |
Computes the size of the union between two bitmaps.
Definition at line 532 of file roaring.hh.
References roaring_bitmap_or_cardinality().
|
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().
|
inlinenoexcept |
Print the content of the bitmap
Definition at line 816 of file roaring.hh.
References roaring_bitmap_printf().
|
inlinenoexcept |
To int array with pagination
Definition at line 424 of file roaring.hh.
References roaring_bitmap_range_uint32_array().
|
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().
|
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().
|
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().
|
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().
|
inlinenoexcept |
|
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().
|
inlinenoexcept |
Remove all values in range [min, max)
Definition at line 276 of file roaring.hh.
References roaring_bitmap_remove_range().
|
inlinenoexcept |
Remove all values in range [min, max]
Definition at line 283 of file roaring.hh.
References roaring_bitmap_remove_range_closed().
|
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().
|
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().
|
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().
|
inlinenoexcept |
Whether or not we apply copy and write.
Definition at line 809 of file roaring.hh.
References roaring_bitmap_set_copy_on_write().
|
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().
|
inlinenoexcept |
Exchange the content of this bitmap with another.
Definition at line 373 of file roaring.hh.
|
inlinenoexcept |
Print the content of the bitmap into a string
Definition at line 821 of file roaring.hh.
|
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().
|
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().
|
inlinenoexcept |
For advanced users.
Definition at line 738 of file roaring.hh.
References roaring_bitmap_frozen_serialize().
|
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().
|
friend |
Definition at line 895 of file roaring.hh.
roaring_bitmap_t roaring::Roaring::roaring |
Definition at line 916 of file roaring.hh.
Referenced by frozenView(), operator&(), operator-(), operator=(), operator^(), operator|(), portableDeserializeFrozen(), Roaring(), and roaring::RoaringSetBitBiDirectionalIterator::RoaringSetBitBiDirectionalIterator().