forked from simongog/sdsl-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcp_vlc.hpp
171 lines (140 loc) · 5.06 KB
/
lcp_vlc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* sdsl - succinct data structures library
Copyright (C) 2010 Simon Gog
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/ .
*/
/* \file lcp_vlc.hpp
\brief lcp_vlc.hpp contains an implementation of a (compressed) LCP array.
\author Simon Gog
*/
#ifndef INCLUDED_SDSL_LCP_VLC
#define INCLUDED_SDSL_LCP_VLC
#include "lcp.hpp"
#include "vlc_vector.hpp"
#include "int_vector.hpp"
#include "algorithms.hpp"
#include "iterators.hpp"
#include <iostream>
#include <cassert>
#include <vector>
namespace sdsl
{
// A class for a compressed LCP array based on variable-length coding.
/*
* \tparam t_vlc_vec Type of the underlying variable-length coder.
*/
template<class t_vlc_vec = vlc_vector<> >
class lcp_vlc
{
public:
typedef typename t_vlc_vec::value_type value_type;
typedef random_access_const_iterator<lcp_vlc> const_iterator;
typedef const_iterator iterator;
typedef const value_type const_reference;
typedef const_reference reference;
typedef const_reference* pointer;
typedef const pointer const_pointer;
typedef typename t_vlc_vec::size_type size_type;
typedef typename t_vlc_vec::difference_type difference_type;
typedef t_vlc_vec vlc_vec_type;
typedef lcp_plain_tag lcp_category;
enum { fast_access = 0,
text_order = 0,
sa_order = 1
};
template<class Cst> // template inner class which is used in CSTs to parametrize lcp classes
class type // with information about the CST. Thanks Stefan Arnold! (2011-03-02)
{
public:
typedef lcp_vlc lcp_type;
};
private:
vlc_vec_type m_vec;
void copy(const lcp_vlc& lcp_c) {
m_vec = lcp_c.m_vec;
}
public:
//! Default Constructor
lcp_vlc() {}
//! Copy constructor
lcp_vlc(const lcp_vlc& lcp_c) {
copy(lcp_c);
}
//! Construct
lcp_vlc(cache_config& config, std::string other_key="");
//! Number of elements in the instance.
size_type size()const {
return m_vec.size();
}
//! Returns the largest size that lcp_vlc can ever have.
static size_type max_size() {
return vlc_vec_type::max_size();
}
//! Returns if the data strucutre is empty.
bool empty()const {
return m_vec.empty();
}
//! Swap method for lcp_vlc
void swap(lcp_vlc& lcp_c) {
m_vec.swap(lcp_c.m_vec);
}
//! Returns a const_iterator to the first element.
const_iterator begin()const {
return const_iterator(this, 0);
}
//! Returns a const_iterator to the element after the last element.
const_iterator end()const {
return const_iterator(this, size());
}
//! []-operator
inline value_type operator[](size_type i)const {
return m_vec[i];
}
//! Assignment Operator.
lcp_vlc& operator=(const lcp_vlc& lcp_c);
//! Serialize to a stream.
size_type serialize(std::ostream& out, structure_tree_node* v=NULL, std::string name="")const;
//! Load from a stream.
void load(std::istream& in) {
m_vec.load(in);
}
};
// == template functions ==
template<class t_vlc_vec>
lcp_vlc<t_vlc_vec>::lcp_vlc(cache_config& config, std::string other_key)
{
std::string lcp_key = constants::KEY_LCP;
if ("" != other_key) {
lcp_key = other_key;
}
int_vector_file_buffer<> lcp_buf(cache_file_name(lcp_key, config));
vlc_vec_type tmp_vec(lcp_buf);
m_vec.swap(tmp_vec);
}
template<class t_vlc_vec>
typename lcp_vlc<t_vlc_vec>::size_type lcp_vlc<t_vlc_vec>::serialize(std::ostream& out, structure_tree_node* v, std::string name)const
{
structure_tree_node* child = structure_tree::add_child(v, name, util::class_name(*this));
size_type written_bytes = 0;
written_bytes += m_vec.serialize(out, child, "vec");
structure_tree::add_size(child, written_bytes);
return written_bytes;
}
template<class t_vlc_vec>
lcp_vlc<t_vlc_vec>& lcp_vlc<t_vlc_vec>::operator=(const lcp_vlc& lcp_c)
{
if (this != &lcp_c) {
copy(lcp_c);
}
return *this;
}
} // end namespace sdsl
#endif