SDSL 3.0.3
Succinct Data Structure Library
Loading...
Searching...
No Matches
lcp_vlc.hpp
Go to the documentation of this file.
1// Copyright (c) 2016, the SDSL Project Authors. All rights reserved.
2// Please see the AUTHORS file for details. Use of this source code is governed
3// by a BSD license that can be found in the LICENSE file.
4/* \file lcp_vlc.hpp
5 * \brief lcp_vlc.hpp contains an implementation of a (compressed) LCP array.
6 * \author Simon Gog
7 */
8#ifndef INCLUDED_SDSL_LCP_VLC
9#define INCLUDED_SDSL_LCP_VLC
10
11#include <iostream>
12#include <string>
13
14#include <sdsl/cereal.hpp>
15#include <sdsl/config.hpp>
17#include <sdsl/io.hpp>
18#include <sdsl/iterators.hpp>
21#include <sdsl/util.hpp>
22#include <sdsl/vlc_vector.hpp>
23
24namespace sdsl
25{
26
27// A class for a compressed LCP array based on variable-length coding.
28/*
29 * \tparam t_vlc_vec Type of the underlying variable-length coder.
30 */
31template <class t_vlc_vec = vlc_vector<>>
33{
34public:
35 typedef typename t_vlc_vec::value_type value_type;
41 typedef const pointer const_pointer;
42 typedef typename t_vlc_vec::size_type size_type;
43 typedef typename t_vlc_vec::difference_type difference_type;
44 typedef t_vlc_vec vlc_vec_type;
45
48
49 enum
50 {
53 sa_order = 1
54 };
55
56 template <class Cst>
57 using type = lcp_vlc;
58
59private:
60 vlc_vec_type m_vec;
61
62public:
64 lcp_vlc() = default;
65
67 lcp_vlc(lcp_vlc const &) = default;
68 lcp_vlc(lcp_vlc &&) = default;
69 lcp_vlc & operator=(lcp_vlc const &) = default;
70 lcp_vlc & operator=(lcp_vlc &&) = default;
71
73 lcp_vlc(cache_config & config, std::string other_key = "")
74 {
75 std::string lcp_key = conf::KEY_LCP;
76 if ("" != other_key)
77 {
78 lcp_key = other_key;
79 }
80 int_vector_buffer<> lcp_buf(cache_file_name(lcp_key, config));
81 m_vec = vlc_vec_type(lcp_buf);
82 }
83
86 {
87 return m_vec.size();
88 }
89
92 {
93 return vlc_vec_type::max_size();
94 }
95
97 bool empty() const
98 {
99 return m_vec.empty();
100 }
101
104 {
105 return const_iterator(this, 0);
106 }
107
110 {
111 return const_iterator(this, size());
112 }
113
116 {
117 return m_vec[i];
118 }
119
121 size_type serialize(std::ostream & out, structure_tree_node * v = nullptr, std::string name = "") const
122 {
123 structure_tree_node * child = structure_tree::add_child(v, name, util::class_name(*this));
124 size_type written_bytes = 0;
125 written_bytes += m_vec.serialize(out, child, "vec");
126 structure_tree::add_size(child, written_bytes);
127 return written_bytes;
128 }
129
131 void load(std::istream & in)
132 {
133 m_vec.load(in);
134 }
135
136 template <typename archive_t>
137 void CEREAL_SAVE_FUNCTION_NAME(archive_t & ar) const
138 {
139 ar(CEREAL_NVP(m_vec));
140 }
141
142 template <typename archive_t>
143 void CEREAL_LOAD_FUNCTION_NAME(archive_t & ar)
144 {
145 ar(CEREAL_NVP(m_vec));
146 }
147
149 bool operator==(lcp_vlc const & other) const noexcept
150 {
151 return (m_vec == other.m_vec);
152 }
153
155 bool operator!=(lcp_vlc const & other) const noexcept
156 {
157 return !(*this == other);
158 }
159};
160
161} // end namespace sdsl
162#endif
cereal.hpp offers cereal support
#define CEREAL_NVP(X)
Definition cereal.hpp:31
static size_type max_size()
Returns the largest size that lcp_vlc can ever have.
Definition lcp_vlc.hpp:91
void CEREAL_LOAD_FUNCTION_NAME(archive_t &ar)
Definition lcp_vlc.hpp:143
random_access_const_iterator< lcp_vlc > const_iterator
Definition lcp_vlc.hpp:36
lcp_vlc(lcp_vlc &&)=default
bool empty() const
Returns if the data strucutre is empty.
Definition lcp_vlc.hpp:97
size_type size() const
Number of elements in the instance.
Definition lcp_vlc.hpp:85
const_iterator iterator
Definition lcp_vlc.hpp:37
const_reference reference
Definition lcp_vlc.hpp:39
lcp_vlc()=default
Default Constructor.
value_type operator[](size_type i) const
[]-operator
Definition lcp_vlc.hpp:115
t_vlc_vec::difference_type difference_type
Definition lcp_vlc.hpp:43
void CEREAL_SAVE_FUNCTION_NAME(archive_t &ar) const
Definition lcp_vlc.hpp:137
const_iterator begin() const
Returns a const_iterator to the first element.
Definition lcp_vlc.hpp:103
lcp_vlc(cache_config &config, std::string other_key="")
Construct.
Definition lcp_vlc.hpp:73
bool operator==(lcp_vlc const &other) const noexcept
Equality operator.
Definition lcp_vlc.hpp:149
bool operator!=(lcp_vlc const &other) const noexcept
Inequality operator.
Definition lcp_vlc.hpp:155
lcp_vlc & operator=(lcp_vlc &&)=default
t_vlc_vec vlc_vec_type
Definition lcp_vlc.hpp:44
t_vlc_vec::value_type value_type
Definition lcp_vlc.hpp:35
const pointer const_pointer
Definition lcp_vlc.hpp:41
void load(std::istream &in)
Load from a stream.
Definition lcp_vlc.hpp:131
lcp_tag index_category
Definition lcp_vlc.hpp:47
lcp_vlc(lcp_vlc const &)=default
Copy / Move constructor.
const value_type const_reference
Definition lcp_vlc.hpp:38
const_iterator end() const
Returns a const_iterator to the element after the last element.
Definition lcp_vlc.hpp:109
lcp_vlc & operator=(lcp_vlc const &)=default
const_reference * pointer
Definition lcp_vlc.hpp:40
t_vlc_vec::size_type size_type
Definition lcp_vlc.hpp:42
lcp_plain_tag lcp_category
Definition lcp_vlc.hpp:46
size_type serialize(std::ostream &out, structure_tree_node *v=nullptr, std::string name="") const
Serialize to a stream.
Definition lcp_vlc.hpp:121
Generic iterator for a random access container.
Definition iterators.hpp:24
static structure_tree_node * add_child(structure_tree_node *v, std::string const &name, std::string const &type)
static void add_size(structure_tree_node *v, uint64_t value)
int_vector_buffer.hpp contains the sdsl::int_vector_buffer class.
io.hpp contains some methods for reading/writing sdsl structures.
iterators.hpp contains an generic iterator for random access containers.
constexpr char KEY_LCP[]
Definition config.hpp:43
Namespace for the succinct data structure library.
std::string cache_file_name(std::string const &key, cache_config const &config)
Returns the file name of the resource.
Definition io.hpp:688
Contains declarations and definitions of data structure concepts.
Helper class for construction process.
Definition config.hpp:66
structure_tree.hpp contains a helper class which can represent the memory structure of a class.
util.hpp contains some helper methods for int_vector and other stuff like demangle class names.
vlc_vector.hpp contains a vector which stores the values with variable length codes.