|
| | RoaringBitmap (void)=default |
| | the empty set
|
| | RoaringBitmap (const RoaringBitmap &o) |
| | a copy, with containers of its own
|
| | RoaringBitmap (RoaringBitmap &&o) noexcept=default |
| | the containers of o, which is left empty
|
| RoaringBitmap & | operator= (RoaringBitmap o) noexcept |
| | the containers of o, a copy or a move (the copy and swap idiom)
|
| | RoaringBitmap (const std::uint32_t *a, std::size_t n) |
| | the set of the \( n \) strictly increasing items of \( a[ 0 .. n ) \), a container per chunk in one scan
|
| bool | contains (std::uint32_t x) const |
| | whether \( x \) is in the set
|
| bool | insert (std::uint32_t x) |
| | \( x \) into the set; true if it was not there
|
| bool | remove (std::uint32_t x) |
| | \( x \) out of the set; true if it was there
|
| std::size_t | size (void) const |
| | the number of items
|
| bool | empty (void) const |
| | whether the set has no item
|
| void | clear (void) |
| | all the items removed
|
| void | swap (RoaringBitmap &o) noexcept |
| | the items of this set and of o exchanged, \( O( 1 ) \)
|
| std::size_t | containers (void) const |
| | the containers \( c \)
|
| std::size_t | bitmaps (void) const |
| | the containers that are bitmaps
|
| std::size_t | bytes (void) const |
| | the bytes of the containers
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( x ) on the items in increasing order
|
| std::vector< std::uint32_t > | items (void) const |
| | the items in increasing order
|
| std::size_t | rank (std::uint32_t x) const |
| | the items smaller than \( x \): the counts of the containers before that of \( x \), \( O( c ) \), and the place of \( x \) in it
|
| std::size_t | portableSizeInBytes (void) const |
| | the bytes of the set in the portable format of Roaring: 8, then 8 per container, 2 per item of an array and 8192 per bitmap
|
| std::size_t | writePortable (std::span< std::byte > out) const |
| | the set written at the start of \( \mathit{out} \) in the portable format of Roaring, with no container of runs; the bytes written
|
| std::vector< std::byte > | writePortable (void) const |
| | the set in the portable format of Roaring, in an array of its own
|
| const_iterator | begin (void) const |
| | the iterator on the smallest item
|
| const_iterator | end (void) const |
| | the iterator past the largest item
|
| const_iterator | cbegin (void) const |
| | as begin()
|
| const_iterator | cend (void) const |
| | as end()
|
| const_iterator | lowerBound (std::uint32_t x) const |
| | the first item not smaller than \( x \), end() if none
|
| const_iterator | select (std::size_t i) const |
| | the item of rank \( i \) (from 0), end() if \( i \ge \) size()
|
a set of integers of 32 bits as a Roaring bitmap
| bool ADS::RoaringBitmap::contains |
( |
std::uint32_t | x | ) |
const |
|
nodiscard |
whether \( x \) is in the set
In pseudocode (Chambi et al.), \( K \) the sorted chunks of the containers:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{contains}( x ) \cr
2 & \quad i \gets \text{the first place of } K \text{ not smaller than }
\lfloor x / 2^{16} \rfloor \text{, by a binary search} \cr
3 & \quad \textbf{if}\ \text{there is none, or } K[ i ] \ne \lfloor x /
2^{16} \rfloor\ \textbf{then return false} \cr
4 & \quad v \gets x \bmod 2^{16} \cr
5 & \quad \textbf{if}\ \text{the container } i \text{ is a bitmap }
\ \textbf{then return}\ \text{its bit } v \cr
6 & \quad \textbf{return}\ v \text{ is in its array, by a binary search}
\end{array}}
\]
| bool ADS::RoaringBitmap::insert |
( |
std::uint32_t | x | ) |
|
\( x \) into the set; true if it was not there
In pseudocode (Chambi et al.):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insert}( x ) \cr
2 & \quad i \gets \text{the container of } \lfloor x / 2^{16} \rfloor
\text{, as in contains} \cr
3 & \quad \textbf{if}\ \text{there is none }\ \textbf{then}
\ \text{insert at } i \text{ the array } ( x \bmod 2^{16} );
\ \textbf{return true} \cr
4 & \quad \text{set the bit, or insert into the array, } x \bmod 2^{16}
\cr
5 & \quad \textbf{if}\ \text{the array passed 4096 items }
\ \textbf{then}\ \text{turn it into a bitmap} \cr
6 & \quad \textbf{return}\ \text{whether } x \text{ was added}
\end{array}}
\]
- Postcondition
- \( x \) is in the set
| const_iterator ADS::RoaringBitmap::lowerBound |
( |
std::uint32_t | x | ) |
const |
|
nodiscard |
the first item not smaller than \( x \), end() if none
In pseudocode (Chambi et al.):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lowerBound}( x ) \cr
2 & \quad i \gets \text{the first container whose chunk is not smaller }
\text{than } \lfloor x / 2^{16} \rfloor \cr
3 & \quad \textbf{if}\ \text{the chunk of } i \text{ is } \lfloor x /
2^{16} \rfloor\ \textbf{then}\ \text{start at the first item of } i
\text{ not smaller than } x \cr
4 & \quad \textbf{else}\ \text{start at the first item of } i \cr
5 & \quad \textbf{return}\ \text{the iterator there, moved to the next }
\text{container while there is no item}
\end{array}}
\]
| std::size_t ADS::RoaringBitmap::rank |
( |
std::uint32_t | x | ) |
const |
|
nodiscard |
the items smaller than \( x \): the counts of the containers before that of \( x \), \( O( c ) \), and the place of \( x \) in it
In pseudocode (Chambi et al.), \( | X_j | \) the items of the container \( j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{rank}( x ) \cr
2 & \quad i \gets \text{the first container whose chunk is not smaller }
\text{than } \lfloor x / 2^{16} \rfloor \cr
3 & \quad \rho \gets \sum_{j < i} | X_j | \cr
4 & \quad \textbf{if}\ \text{the chunk of } i \text{ is }
\lfloor x / 2^{16} \rfloor\ \textbf{then}\ \rho \gets \rho +
\text{the items of } X_i \text{ below } x \bmod 2^{16} \cr
5 & \quad \textbf{return}\ \rho
\end{array}}
\]
| bool ADS::RoaringBitmap::remove |
( |
std::uint32_t | x | ) |
|
\( x \) out of the set; true if it was there
In pseudocode (Chambi et al.), the converse of insert():
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{remove}( x ) \cr
2 & \quad i \gets \text{the container of } \lfloor x / 2^{16} \rfloor
;\ \textbf{if}\ \text{there is none }\ \textbf{then return false} \cr
3 & \quad \text{clear the bit, or remove from the array, } x \bmod 2^{16}
\cr
4 & \quad \textbf{if}\ \text{the container is empty }\ \textbf{then}
\ \text{remove it} \cr
5 & \quad \textbf{else if}\ \text{a bitmap fell to 4096 items }
\ \textbf{then}\ \text{turn it into an array} \cr
6 & \quad \textbf{return}\ \text{whether } x \text{ was there}
\end{array}}
\]
- Postcondition
- \( x \) is not in the set
the item of rank \( i \) (from 0), end() if \( i \ge \) size()
In pseudocode (Chambi et al.), \( | X_j | \) the items of the container \( j \) and \( W_k \) the words of a bitmap:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{select}( i ) \cr
2 & \quad j \gets 0;\ \textbf{while}\ i \ge | X_j |\ \textbf{do}\ i \gets
i - | X_j |;\ j \gets j + 1 \cr
3 & \quad \textbf{if}\ X_j \text{ is an array }\ \textbf{then}\ v \gets
X_j[ i ] \cr
4 & \quad \textbf{else} \cr
5 & \qquad k \gets 0;\ \textbf{while}\ i \ge \mathrm{popcount}( W_k )
\ \textbf{do}\ i \gets i - \mathrm{popcount}( W_k );\ k \gets k + 1
\cr
6 & \qquad v \gets 64 k + \text{the place of the bit set of rank } i
\text{ of } W_k \cr
7 & \quad \textbf{return}\ \mathrm{lowerBound}( 2^{16} \cdot
\text{the chunk of } X_j + v )
\end{array}}
\]
the difference, by the merge of the containers
In pseudocode (Chambi et al.), the containers merged by their chunks:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{setDifference}( A , B ) \cr
2 & \quad C \gets \text{an empty set} \cr
3 & \quad \textbf{foreach}\ \text{chunk } k \text{ of } A \text{ or } B
\text{, in increasing order}\ \textbf{do} \cr
4 & \qquad \textbf{if}\ \text{both have } k\ \textbf{then}\ X \gets
\text{the difference of their two containers} \cr
5 & \qquad \textbf{else}\ X \gets \text{a copy of the container of } A
\text{, if it has it} \cr
6 & \qquad \textbf{if}\ X \text{ is not empty }\ \textbf{then}
\ \text{append } X \text{ to } C \cr
7 & \quad \textbf{return}\ C
\end{array}}
\]
the intersection, by the merge of the containers
In pseudocode (Chambi et al.), the containers merged by their chunks:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{setIntersection}( A , B ) \cr
2 & \quad C \gets \text{an empty set} \cr
3 & \quad \textbf{foreach}\ \text{chunk } k \text{ of } A \text{ or } B
\text{, in increasing order}\ \textbf{do} \cr
4 & \qquad \textbf{if}\ \text{both have } k\ \textbf{then}\ X \gets
\text{the intersection of their two containers} \cr
5 & \qquad \textbf{else}\ X \gets \text{nothing} \cr
6 & \qquad \textbf{if}\ X \text{ is not empty }\ \textbf{then}
\ \text{append } X \text{ to } C \cr
7 & \quad \textbf{return}\ C
\end{array}}
\]
the symmetric difference, by the merge of the containers
In pseudocode (Chambi et al.), the containers merged by their chunks:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{setSymmetricDifference}( A , B ) \cr
2 & \quad C \gets \text{an empty set} \cr
3 & \quad \textbf{foreach}\ \text{chunk } k \text{ of } A \text{ or } B
\text{, in increasing order}\ \textbf{do} \cr
4 & \qquad \textbf{if}\ \text{both have } k\ \textbf{then}\ X \gets
\text{the symmetric difference of their two containers} \cr
5 & \qquad \textbf{else}\ X \gets \text{a copy of the container of the }
\text{one that has it} \cr
6 & \qquad \textbf{if}\ X \text{ is not empty }\ \textbf{then}
\ \text{append } X \text{ to } C \cr
7 & \quad \textbf{return}\ C
\end{array}}
\]
the union, by the merge of the containers
In pseudocode (Chambi et al.), the containers merged by their chunks:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{setUnion}( A , B ) \cr
2 & \quad C \gets \text{an empty set} \cr
3 & \quad \textbf{foreach}\ \text{chunk } k \text{ of } A \text{ or } B
\text{, in increasing order}\ \textbf{do} \cr
4 & \qquad \textbf{if}\ \text{both have } k\ \textbf{then}\ X \gets
\text{the union of their two containers} \cr
5 & \qquad \textbf{else}\ X \gets \text{a copy of the container of the }
\text{one that has it} \cr
6 & \qquad \textbf{if}\ X \text{ is not empty }\ \textbf{then}
\ \text{append } X \text{ to } C \cr
7 & \quad \textbf{return}\ C
\end{array}}
\]