22 static_assert(block_size <= 64,
"block_size cannot be larger than 64 bits");
27 size_t m_supblock_size;
41 m_supblock_size(other.m_supblock_size),
42 m_blocks(other.m_blocks),
43 m_supblocks(other.m_supblocks) {
49 m_supblock_size(other.m_supblock_size),
50 m_blocks(
std::move(other.m_blocks)),
51 m_supblocks(
std::move(other.m_supblocks)) {
57 m_supblock_size = other.m_supblock_size;
58 m_blocks = other.m_blocks;
59 m_supblocks = other.m_supblocks;
66 m_supblock_size = other.m_supblock_size;
67 m_blocks = std::move(other.m_blocks);
68 m_supblocks = std::move(other.m_supblocks);
81 m_supblock_size(block_size * block_size) {
83 DCHECK_GT(m_supblock_size, block_size)
84 <<
"superblocks must be larger than blocks!";
85 DCHECK_EQ(0, m_supblock_size % block_size)
86 <<
"superblock size must be a multiple of the block size!";
88 const size_t n = m_bv->
size();
89 const auto data = m_bv->
data();
92 const size_t num_supblocks =
idiv_ceil(n, m_supblock_size);
93 const size_t num_blocks =
idiv_ceil(n, block_size);
95 const size_t blocks_per_supblock = m_supblock_size /
block_size;
105 for(
size_t j = 0; j < num_blocks; j++) {
106 size_t i = j / blocks_per_supblock;
109 m_supblocks[cur_sb] = rank_bv;
118 m_blocks[j] = rank_sb;
126 inline size_t rank1(
size_t x)
const {
127 DCHECK_LT(x, m_bv->
size());
129 size_t i = x / m_supblock_size;
130 if(i > 0) r += m_supblocks[i-1];
133 size_t k = j - i * (m_supblock_size /
block_size);
134 if(k > 0) r += m_blocks[j-1];
145 inline size_t rank1(
size_t x,
size_t y)
const {
148 if(x > 0) r -=
rank1(x-1);
166 inline size_t rank0(
size_t x)
const {
167 return x + 1 -
rank1(x);
175 inline size_t rank0(
size_t x,
size_t y)
const {
176 return (y - x + 1) -
rank1(x, y);
static constexpr size_t block_size
The size of a block in bits.
Contains the text compression and encoding framework.
constexpr uint_fast8_t bits_for(size_t n)
Computes the number of bits required to store the given integer value.
constexpr size_t idiv_ceil(size_t a, size_t b)
Performs an integer division with the result rounded up to the next integer.
size_t rank1(size_t x, size_t y) const
Counts the amount of 1-bits in the given interval (borders included) of the bit vector.
A vector over arbitrary unsigned integer types.
Implements a rank data structure for a BitVector.
size_t rank0(size_t x) const
Counts the amount of 0-bits from the beginning of the bit vector up to (including) the given position...
size_t operator()(size_t x, size_t y) const
Rank(const Rank &other)
Copy constructor.
size_t rank0(size_t x, size_t y) const
Counts the amount of 0-bits in the given interval (borders included) of the bit vector.
Rank(const BitVector &bv)
Constructs the rank data structure for the given bit vector.
constexpr uint8_t rank1(uint8_t v)
Computes the amount of 1-bits in the binary representation of the given 8-bit value.
size_t operator()(size_t x) const
IntVectorTrait< T >::internal_data_type internal_data_type
The element type of the internal data buffer accessed with data()
internal_data_type * data() noexcept
size_t rank1(size_t x) const
Counts the amount of 1-bits from the beginning of the bit vector up to (including) the given position...
Rank(Rank &&other)
Move constructor.
Rank & operator=(Rank &&other)
Move assignment.
Rank & operator=(const Rank &other)
Copy assignment.
IntVector< dynamic_t > DynamicIntVector
Represents an integer vector with unspecified (dynamic) bit width.
Rank()
Default constructor.