19template <u
int8_t t_w
idth>
38template <
class t_coder = coder::elias_delta<>, u
int32_t t_dens = 128, u
int8_t t_w
idth = 0>
42 static_assert(t_dens > 1,
"vlc_vector: Sampling density must be larger than 1");
62 uint32_t m_sample_dens = t_dens;
69 m_sample_pointer.
resize(0);
84 template <
class Container>
88 template <u
int8_t
int_w
idth>
97 bool empty()
const {
return 0 == m_size; }
107 return m_size && v.m_size &&
m_z == v.
m_z && m_sample_pointer == v.m_sample_pointer;
119 void load(std::istream & in);
122 template <
typename archive_t>
126 template <
typename archive_t>
136template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
140 return m_sample_dens;
145template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
148 m_sample_dens = sdens;
151template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
158 return (t_coder::template decode<false, false, int *>(m_z.data(), m_sample_pointer[idx], i - t_dens * idx + 1)) - 1;
161template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
162template <
class Container>
173 if (c[i] + 1 < 1) {
throw std::logic_error(
"vlc_vector cannot decode values smaller than 1!"); }
174 z_size += t_coder::encoding_length(c[i] + 1);
176 samples = (c.size() + get_sample_dens() - 1) / get_sample_dens();
180 m_z.bit_resize(z_size);
182 uint64_t * z_data = t_coder::raw_data(m_z);
185 for (
size_type i = 0, sample_cnt = 0; i < c.size(); ++i, --no_sample)
189 no_sample = get_sample_dens();
190 m_sample_pointer[sample_cnt++] = z_size;
192 t_coder::encode(c[i] + 1, z_data, offset);
193 z_size += t_coder::encoding_length(c[i] + 1);
198template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
199template <u
int8_t
int_w
idth>
211 if (x < 1) {
throw std::logic_error(
"vlc_vector cannot decode values smaller than 1!"); }
212 z_size += t_coder::encoding_length(x);
214 samples = (n + get_sample_dens() - 1) / get_sample_dens();
220 m_z.bit_resize(z_size);
222 uint64_t * z_data = t_coder::raw_data(m_z);
227 for (
size_type i = 0, sample_cnt = 0; i < n; ++i, --no_sample)
231 no_sample = get_sample_dens();
232 m_sample_pointer[sample_cnt++] = z_size;
235 t_coder::encode(x, z_data, offset);
236 z_size += t_coder::encoding_length(x);
241template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
244 std::string name)
const
248 written_bytes +=
write_member(m_size, out, child,
"m_size");
249 written_bytes += m_z.serialize(out, child,
"m_z");
250 written_bytes += m_sample_pointer.serialize(out, child,
"m_sample_pointer");
252 return written_bytes;
255template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
260 m_sample_pointer.load(in);
263template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
264template <
typename archive_t>
272template <
class t_coder, u
int32_t t_dens, u
int8_t t_w
idth>
273template <
typename archive_t>
#define CEREAL_LOAD_FUNCTION_NAME
#define CEREAL_SAVE_FUNCTION_NAME
uint64_t size() const
Returns the number of elements currently stored.
A generic vector class for integers of width .
void shrink_to_fit()
Free unused allocated memory.
static size_type max_size() noexcept
Maximum size of the int_vector.
void resize(const size_type size)
Resize the int_vector in terms of elements.
Generic iterator for a random access container.
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)
A generic immutable space-saving vector class for unsigned integers.
static const uint32_t sample_dens
const const_iterator end() const
Iterator that points to the position after the last element of the vlc_vector.
vlc_vector & operator=(vlc_vector &&)=default
random_access_const_iterator< vlc_vector > iterator
const const_iterator begin() const
Iterator that points to the first element of the vlc_vector.
vlc_vector(vlc_vector &&)=default
vlc_vector(const vlc_vector &)=default
bool operator!=(const vlc_vector &v) const
vlc_vector_trait< t_width >::int_vector_type int_vector_type
bool operator==(const vlc_vector &v) const
size_type size() const
The number of elements in the vlc_vector.
ptrdiff_t difference_type
void load(std::istream &in)
Load the vlc_vector from a stream.
value_type sample(const size_type i) const
Returns the ith sample of vlc_vector.
uint32_t get_sample_dens() const
void CEREAL_LOAD_FUNCTION_NAME(archive_t &ar)
Serialise (load) via cereal.
const value_type * const_pointer
void set_sample_dens(const uint32_t sdens)
const value_type reference
const value_type const_reference
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
Serializes the vlc_vector to a stream.
int_vector ::size_type size_type
bool empty() const
Returns if the vlc_vector is empty.
vlc_vector & operator=(const vlc_vector &)=default
static size_type max_size()
Return the largest size that this container can ever have.
void CEREAL_SAVE_FUNCTION_NAME(archive_t &ar) const
Serialise (save) via cereal.
value_type operator[](size_type i) const
[]-operator
coder_elias_delta.hpp contains the class sdsl::coder::elias_delta
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)
static constexpr uint32_t hi(uint64_t x)
Position of the most significant set bit the 64-bit word x.
int_vector< 32 > int_vector_type
int_vector< 0 > int_vector_type