CRoaring
3.0.0
Roaring bitmaps in C (and C++)
|
#include <roaring.hh>
Public Types | |
typedef RoaringSetBitForwardIterator | const_iterator |
Public Member Functions | |
Roaring () | |
Roaring (size_t n, const uint32_t *data) | |
Roaring (std::initializer_list< uint32_t > l) | |
Roaring (const Roaring &r) | |
Roaring (Roaring &&r) noexcept | |
Roaring (roaring_bitmap_t *s) noexcept | |
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 |
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 |
~Roaring () | |
Roaring & | operator= (const Roaring &r) |
Roaring & | operator= (Roaring &&r) noexcept |
Roaring & | operator= (std::initializer_list< uint32_t > l) |
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 | 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 |
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 |
Definition at line 66 of file roaring.hh.
Definition at line 871 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 74 of file roaring.hh.
|
inline |
Construct a bitmap from a list of 32-bit integer values.
Definition at line 83 of file roaring.hh.
|
inline |
Construct a bitmap from an initializer list.
Definition at line 90 of file roaring.hh.
|
inline |
Copy constructor. It may throw std::runtime_error if there is insufficient memory.
Definition at line 98 of file roaring.hh.
References roaring, 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 110 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 127 of file roaring.hh.
|
inline |
Destructor. By contract, calling roaring_bitmap_clear() is enough to release all auxiliary memory used by the structure.
Definition at line 277 of file roaring.hh.
|
inlinenoexcept |
Add value x
Definition at line 158 of file roaring.hh.
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 198 of file roaring.hh.
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 165 of file roaring.hh.
Referenced by roaring::Roaring64Map::addChecked().
|
inlinenoexcept |
Add value n_args from pointer vals
Definition at line 186 of file roaring.hh.
Referenced by roaring::Roaring64Map::addMany(), and bitmapOfList().
|
inlinenoexcept |
Add all values in range [min, max)
Definition at line 172 of file roaring.hh.
|
inlinenoexcept |
Add all values in range [min, max]
Definition at line 179 of file roaring.hh.
Referenced by roaring::Roaring64Map::addRangeClosed().
|
inlinenoexcept |
Computes the size of the intersection between two bitmaps.
Definition at line 504 of file roaring.hh.
|
inlinenoexcept |
Computes the size of the difference (andnot) between two bitmaps.
Definition at line 536 of file roaring.hh.
|
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 988 of file roaring.hh.
|
inlinestatic |
Construct a bitmap from a list of uint32_t values.
Definition at line 134 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 149 of file roaring.hh.
References addMany().
|
inlinenoexcept |
Get the cardinality of the bitmap (number of elements).
Definition at line 385 of file roaring.hh.
|
inlinenoexcept |
Check if value x is present
Definition at line 262 of file roaring.hh.
|
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 210 of file roaring.hh.
|
inlinenoexcept |
Check if all values from x (included) to y (excluded) are present
Definition at line 269 of file roaring.hh.
|
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 992 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 853 of file roaring.hh.
References 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 437 of file roaring.hh.
|
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 445 of file roaring.hh.
|
inlinestatic |
For advanced users. This function may throw std::runtime_error.
Definition at line 706 of file roaring.hh.
References roaring, and ROARING_TERMINATE.
Referenced by roaring::Roaring64Map::frozenView().
|
inlinenoexcept |
Whether or not copy and write is active.
Definition at line 844 of file roaring.hh.
|
inlinenoexcept |
For advanced users.
Definition at line 742 of file roaring.hh.
|
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 577 of file roaring.hh.
|
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 694 of file roaring.hh.
Referenced by roaring::Roaring64Map::portableDeserializeFrozen(), roaring::Roaring64Map::read(), and roaring::Roaring64Map::readSafe().
|
inlinenoexcept |
Check whether the two bitmaps intersect.
Definition at line 511 of file roaring.hh.
|
inlinenoexcept |
Returns true if the bitmap is empty (cardinality is zero).
Definition at line 392 of file roaring.hh.
|
inlinenoexcept |
Returns true if the bitmap is strict subset of the other.
Definition at line 406 of file roaring.hh.
|
inlinenoexcept |
Returns true if the bitmap is subset of the other.
Definition at line 399 of file roaring.hh.
|
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 485 of file roaring.hh.
|
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 522 of file roaring.hh.
|
inlinenoexcept |
Return the largest value (if not empty)
Definition at line 248 of file roaring.hh.
|
inlinenoexcept |
Return the smallest value (if not empty)
Definition at line 255 of file roaring.hh.
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 756 of file roaring.hh.
References roaring::BulkContext::Roaring, roaring, 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 340 of file roaring.hh.
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 769 of file roaring.hh.
References roaring::BulkContext::Roaring, roaring, 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 350 of file roaring.hh.
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 299 of file roaring.hh.
References roaring, and ROARING_TERMINATE.
Moves the content of the provided bitmap, and discard the current content.
Definition at line 312 of file roaring.hh.
|
inline |
Assignment from an initializer list.
Definition at line 326 of file roaring.hh.
References roaring::BulkContext::Roaring.
|
inlinenoexcept |
Return true if the two bitmaps contain the same elements.
Definition at line 429 of file roaring.hh.
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 795 of file roaring.hh.
References roaring::BulkContext::Roaring, roaring, 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 372 of file roaring.hh.
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 782 of file roaring.hh.
References roaring::BulkContext::Roaring, roaring, 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 362 of file roaring.hh.
|
inlinenoexcept |
Computes the size of the union between two bitmaps.
Definition at line 529 of file roaring.hh.
|
inlinestatic |
For advanced users; see roaring_bitmap_portable_deserialize_frozen. This function may throw std::runtime_error.
Definition at line 721 of file roaring.hh.
References roaring, and ROARING_TERMINATE.
Referenced by roaring::Roaring64Map::portableDeserializeFrozen().
|
inlinenoexcept |
Print the content of the bitmap
Definition at line 813 of file roaring.hh.
|
inlinenoexcept |
To int array with pagination
Definition at line 421 of file roaring.hh.
|
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 556 of file roaring.hh.
|
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 565 of file roaring.hh.
|
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 644 of file roaring.hh.
References roaring::BulkContext::Roaring, 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 677 of file roaring.hh.
References roaring::BulkContext::Roaring, and ROARING_TERMINATE.
Referenced by roaring::Roaring64Map::readSafe().
|
inlinenoexcept |
Remove value x
Definition at line 218 of file roaring.hh.
|
inlinenoexcept |
Remove value x Returns true if a new value was removed, false if the value was not existing.
Definition at line 227 of file roaring.hh.
|
inlinenoexcept |
Remove all values in range [min, max)
Definition at line 234 of file roaring.hh.
|
inlinenoexcept |
Remove all values in range [min, max]
Definition at line 241 of file roaring.hh.
|
inlinenoexcept |
Remove run-length encoding even when it is more space efficient. Return whether a change was applied.
Definition at line 454 of file roaring.hh.
|
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 464 of file roaring.hh.
|
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 497 of file roaring.hh.
|
inlinenoexcept |
Whether or not we apply copy and write.
Definition at line 806 of file roaring.hh.
|
inlinenoexcept |
If needed, reallocate memory to shrink the memory usage. Returns the number of bytes saved.
Definition at line 472 of file roaring.hh.
|
inlinenoexcept |
Exchange the content of this bitmap with another.
Definition at line 380 of file roaring.hh.
|
inlinenoexcept |
Print the content of the bitmap into a string
Definition at line 818 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 415 of file roaring.hh.
|
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 620 of file roaring.hh.
|
inlinenoexcept |
For advanced users.
Definition at line 735 of file roaring.hh.
|
inlinenoexcept |
Computes the size of the symmetric difference (andnot) between two bitmaps.
Definition at line 544 of file roaring.hh.
roaring_bitmap_t roaring::Roaring::roaring |
Definition at line 890 of file roaring.hh.
Referenced by frozenView(), operator&(), operator-(), operator=(), operator^(), operator|(), portableDeserializeFrozen(), Roaring(), and roaring::RoaringSetBitForwardIterator::RoaringSetBitForwardIterator().