8 #ifndef INCLUDED_SDSL_RANK_SUPPORT_V
9 #define INCLUDED_SDSL_RANK_SUPPORT_V
38 template <u
int8_t t_b = 1, u
int8_t t_pat_len = 1>
42 static_assert(t_b == 1u or t_b == 0u or t_b == 10u or t_b == 11,
43 "rank_support_v: bit pattern must be `0`,`1`,`10` or `01`");
44 static_assert(t_pat_len == 1u or t_pat_len == 2u,
"rank_support_v: bit pattern length must be 1 or 2");
66 if (v ==
nullptr) {
return; }
72 size_type basic_block_size = (((v->bit_size() + 63) >> 9) + 1) << 1;
73 m_basic_block.
resize(basic_block_size);
74 if (m_basic_block.
empty())
return;
75 const uint64_t * data =
m_v->
data();
77 m_basic_block[0] = m_basic_block[1] = 0;
81 uint64_t second_level_cnt = 0;
87 m_basic_block[j - 1] = second_level_cnt;
88 m_basic_block[j] = m_basic_block[j - 2] + sum;
89 second_level_cnt = sum = 0;
93 second_level_cnt |= sum << (63 - 9 * (i & 0x7));
99 second_level_cnt |= sum << (63 - 9 * (i & 0x7));
100 m_basic_block[j + 1] = second_level_cnt;
105 m_basic_block[j - 1] = second_level_cnt;
106 m_basic_block[j] = m_basic_block[j - 2] + sum;
107 m_basic_block[j + 1] = 0;
118 assert(
m_v !=
nullptr);
119 assert(idx <= m_v->
size());
120 const uint64_t * p = m_basic_block.
data() + ((idx >> 8) & 0xFFFFFFFFFFFFFFFEULL);
122 return *p + ((*(p + 1) >> (63 - 9 * ((idx & 0x1FF) >> 6))) & 0x1FF) +
125 return *p + ((*(p + 1) >> (63 - 9 * ((idx & 0x1FF) >> 6))) & 0x1FF);
136 written_bytes += m_basic_block.
serialize(out, child,
"cumulative_counts");
138 return written_bytes;
144 m_basic_block.
load(in);
147 template <
typename archive_t>
153 template <
typename archive_t>
bool empty() const noexcept
Equivalent to size() == 0.
size_type bit_size() const noexcept
The number of bits in the int_vector.
const uint64_t * data() const noexcept
Pointer to the raw data of the int_vector.
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.
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.
A rank structure proposed by Sebastiano Vigna.
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
Serializes rank_support.
rank_support_trait< t_b, t_pat_len > trait_type
size_type rank(size_type idx) const
Answers rank queries for the supported bit_vector.
bool operator!=(const rank_support_v &other) const noexcept
void CEREAL_LOAD_FUNCTION_NAME(archive_t &ar)
rank_support_v & operator=(rank_support_v &&)=default
bit_vector bit_vector_type
rank_support_v(const rank_support_v &)=default
bool operator==(const rank_support_v &other) const noexcept
size_type operator()(size_type idx) const
Alias for rank(i)
void set_vector(const bit_vector *v=nullptr)
Sets the supported bit_vector to the given pointer.
void load(std::istream &in, const int_vector< 1 > *v=nullptr)
Loads the rank_support.
rank_support_v & operator=(const rank_support_v &)=default
rank_support_v(rank_support_v &&)=default
rank_support_v(const bit_vector *v=nullptr)
void CEREAL_SAVE_FUNCTION_NAME(archive_t &ar) const
The base class of classes supporting rank_queries for a sdsl::bit_vector in constant time.
const bit_vector * m_v
Pointer to the rank supported bit_vector.
bit_vector::size_type size_type
static void add_size(structure_tree_node *v, uint64_t value)
static structure_tree_node * add_child(structure_tree_node *v, const std::string &name, const std::string &type)
Namespace for the succinct data structure library.
rank_support.hpp contains classes that support a sdsl::bit_vector with constant time rank information...
static uint32_t word_rank(const uint64_t *, size_type)
static uint64_t init_carry()
static size_type args_in_the_word(uint64_t, uint64_t &)