9#ifndef SDSL_BIT_VECTOR_IL
10#define SDSL_BIT_VECTOR_IL
22template <u
int8_t t_b = 1, u
int32_t t_bs = 512>
25template <u
int8_t t_b = 1, u
int32_t t_bs = 512>
31 return std::is_integral<T>::value and x > 1 and !(x & (x - 1));
43template <u
int32_t t_bs = 512>
46 static_assert(t_bs >= 64,
"bit_vector_il: blocksize must be be at least 64 bits.");
47 static_assert(
power_of_two(t_bs),
"bit_vector_il: blocksize must be a power of two.");
76 void init_rank_samples()
78 uint32_t blockSize_U64 =
bits::hi(t_bs >> 6);
80 std::queue<size_type> lbs, rbs;
82 rbs.push(m_superblocks);
89 if ( idx < m_rank_samples.
size())
92 size_type pos = (mid << blockSize_U64) + mid;
93 m_rank_samples[idx++] = m_data[pos];
114 m_superblocks = (m_size + t_bs) / t_bs;
118 size_type mem = blocks + m_superblocks + 1;
125 const uint64_t * bvp = bv.
data();
130 for (
size_type i = 0, sample_cnt = sample_rate; i < blocks; ++i, ++sample_cnt)
132 if (sample_cnt == sample_rate)
144 if (m_block_num > 1024 * 64)
149 m_rank_samples.
resize(std::min(1024ULL, 1ULL <<
bits::hi(m_superblocks)));
165 return ((m_data[block] >> (i & 63)) & 1ULL);
178 assert(idx + len - 1 < m_size);
181 bs = (idx + len - 1) >> m_block_shift;
182 size_type e_block = bs + ((idx + len - 1) >> 6) + 1;
183 if (b_block == e_block)
185 return (m_data[b_block] >> (idx & 63)) &
bits::lo_set[len];
189 uint8_t b_len = 64 - (idx & 63);
190 return (m_data[b_block] >> (idx & 63)) | (m_data[e_block] &
bits::lo_set[len - b_len]) << b_len;
202 written_bytes +=
write_member(m_size, out, child,
"size");
203 written_bytes +=
write_member(m_block_num, out, child,
"block_num");
204 written_bytes +=
write_member(m_superblocks, out, child,
"superblocks");
205 written_bytes +=
write_member(m_block_shift, out, child,
"block_shift");
206 written_bytes += m_data.
serialize(out, child,
"data");
207 written_bytes += m_rank_samples.
serialize(out, child,
"rank_samples");
209 return written_bytes;
220 m_rank_samples.
load(in);
223 template <
typename archive_t>
234 template <
typename archive_t>
254template <u
int8_t t_b, u
int32_t t_bs>
257 static_assert(t_b == 1 or t_b == 0,
"rank_support_il only supports bitpatterns 0 or 1.");
279 size_type SBlockNum = i >> m_block_shift;
280 size_type SBlockPos = (SBlockNum << m_block_size_U64) + SBlockNum;
281 uint64_t resp = m_v->m_data[SBlockPos];
282 const uint64_t * B = (m_v->m_data.data() + (SBlockPos + 1));
283 uint64_t rem = i & 63;
284 uint64_t
bits = (i & m_block_mask) - rem;
296 size_type SBlockNum = i >> m_block_shift;
297 size_type SBlockPos = (SBlockNum << m_block_size_U64) + SBlockNum;
298 uint64_t resp = (SBlockNum << m_block_shift) - m_v->m_data[SBlockPos];
299 const uint64_t * B = (m_v->m_data.data() + (SBlockPos + 1));
300 uint64_t rem = i & 63;
301 uint64_t
bits = (i & m_block_mask) - rem;
317 m_block_mask = t_bs - 1;
318 m_block_size_U64 =
bits::hi(t_bs >> 6);
324 if (t_b)
return rank1(i);
347 template <
typename archive_t>
351 template <
typename archive_t>
360template <u
int8_t t_b, u
int32_t t_bs>
363 static_assert(t_b == 1 or t_b == 0,
"select_support_il only supports bitpatterns 0 or 1.");
386 size_type lb = 0, rb = m_v->m_superblocks;
396 if (idx < m_v->m_rank_samples.size())
398 if (m_v->m_rank_samples[idx] >= i)
400 idx = (idx << 1) + 1;
405 idx = (idx << 1) + 2;
412 size_type pos = (mid << m_block_size_U64) + mid;
415 if (m_v->m_data[pos] >= i) { rb = mid; }
424 res = (rb - 1) << m_block_shift;
426 const uint64_t * w = m_v->m_data.data() + ((rb - 1) << m_block_size_U64) + (rb - 1);
445 size_type lb = 0, rb = m_v->m_superblocks;
455 if (idx < m_v->m_rank_samples.size())
457 if (((mid << m_block_shift) - m_v->m_rank_samples[idx]) >= i)
459 idx = (idx << 1) + 1;
464 idx = (idx << 1) + 2;
471 size_type pos = (mid << m_block_size_U64) + mid;
474 if (((mid << m_block_shift) - m_v->m_data[pos]) >= i) { rb = mid; }
483 res = (rb - 1) << m_block_shift;
486 const uint64_t * w = m_v->m_data.data() + ((rb - 1) << m_block_size_U64) + (rb - 1);
507 m_block_size_U64 =
bits::hi(t_bs >> 6);
513 if (t_b)
return select1(i);
536 template <
typename archive_t>
540 template <
typename archive_t>
A bit vector which interleaves the original bit_vector with rank information.
bit_vector_il(bit_vector_il &&)=default
void CEREAL_SAVE_FUNCTION_NAME(archive_t &ar) const
void load(std::istream &in)
Loads the data structure from the given istream.
bit_vector_il(const bit_vector_il &)=default
bit_vector::difference_type difference_type
bit_vector_il & operator=(const bit_vector_il &)=default
value_type operator[](size_type i) const
Accessing the i-th element of the original bit_vector.
uint64_t get_int(size_type idx, uint8_t len=64) const
Get the integer value of the binary string of length len starting at position idx.
bit_vector_il & operator=(bit_vector_il &&)=default
select_support_il< 1, t_bs > select_1_type
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
Serializes the data structure into the given ostream.
bool operator==(const bit_vector_il &v) const
bool operator!=(const bit_vector_il &v) const
size_type size() const
Returns the size of the original bit vector.
select_support_il< 0, t_bs > select_0_type
rank_support_il< 1, t_bs > rank_1_type
random_access_const_iterator< bit_vector_il > iterator
bit_vector_il(const bit_vector &bv)
bit_vector::size_type size_type
rank_support_il< 0, t_bs > rank_0_type
void CEREAL_LOAD_FUNCTION_NAME(archive_t &ar)
A generic vector class for integers of width .
int_vector_size_type size_type
ptrdiff_t difference_type
void load(std::istream &in)
Load the int_vector for a stream.
size_type size() const noexcept
The number of elements in the int_vector.
const uint64_t * data() const noexcept
Pointer to the raw data of the int_vector.
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
Serializes the int_vector to a stream.
void resize(const size_type size)
Resize the int_vector in terms of elements.
Generic iterator for a random access container.
void set_vector(const bit_vector_type *v=nullptr)
bool operator==(const rank_support_il &other) const noexcept
rank_support_il(const bit_vector_type *v=nullptr)
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
void load(std::istream &, const bit_vector_type *v=nullptr)
size_type rank(size_type i) const
Returns the position of the i-th occurrence in the bit vector.
rank_support_il & operator=(const rank_support_il &rs)
size_type operator()(size_type i) const
bit_vector_il< t_bs > bit_vector_type
bool operator!=(const rank_support_il &other) const noexcept
void CEREAL_SAVE_FUNCTION_NAME(archive_t &) const
void CEREAL_LOAD_FUNCTION_NAME(archive_t &)
bit_vector::size_type size_type
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
size_type select(size_type i) const
Returns the position of the i-th occurrence in the bit vector.
bool operator!=(const select_support_il &other) const noexcept
size_type operator()(size_type i) const
void CEREAL_SAVE_FUNCTION_NAME(archive_t &) const
bool operator==(const select_support_il &other) const noexcept
select_support_il(const bit_vector_type *v=nullptr)
void CEREAL_LOAD_FUNCTION_NAME(archive_t &)
bit_vector_il< t_bs > bit_vector_type
void load(std::istream &, const bit_vector_type *v=nullptr)
bit_vector::size_type size_type
void set_vector(const bit_vector_type *v=nullptr)
select_support_il & operator=(const select_support_il &rs)
static structure_tree_node * add_child(structure_tree_node *v, const std::string &name, const std::string &type)
static void add_size(structure_tree_node *v, uint64_t value)
int_vector.hpp contains the sdsl::int_vector class.
iterators.hpp contains an generic iterator for random access containers.
Namespace for the succinct data structure library.
size_t write_member(const T &t, std::ostream &out, sdsl::structure_tree_node *v=nullptr, std::string name="")
void read_member(T &t, std::istream &in)
constexpr bool power_of_two(T x)
size_t serialize_empty_object(std::ostream &, structure_tree_node *v=nullptr, std::string name="", const T *t=nullptr)
A helper class for bitwise tricks on 64 bit words.
static constexpr uint32_t sel(uint64_t x, uint32_t i)
Calculate the position of the i-th rightmost 1 bit in the 64bit integer x.
static constexpr uint32_t hi(uint64_t x)
Position of the most significant set bit the 64-bit word x.
static constexpr uint64_t cnt(uint64_t x)
Counts the number of set bits in x.
static constexpr uint64_t lo_set[65]
lo_set[i] is a 64-bit word with the i least significant bits set and the high bits not set.
util.hpp contains some helper methods for int_vector and other stuff like demangle class names.