Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
SuffixArray.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <ext/iostream>
27#include <ext/algorithm>
28
29#include <alib/string>
30#include <alib/set>
31#include <alib/trie>
32
34
36
37#include <string/LinearString.h>
38
40
41namespace indexes {
42
43namespace stringology {
44
50template < class SymbolType = DefaultSymbolType >
51class SuffixArray final {
56
61
62public:
70
76 const ext::vector < unsigned > & getData ( ) const &;
77
84
91
98
105 return m_string.getAlphabet ( );
106 }
107
114 return std::move ( m_string ).getAlphabet ( );
115 }
116
122 void setData ( ext::vector < unsigned > data );
123
129 bool removeSymbolFromAlphabet ( const SymbolType & symbol ) {
130 return m_string.removeSymbol ( symbol );
131 }
132
140 auto operator <=> ( const SuffixArray & other ) const {
141 return std::tie ( getData ( ), getString ( ) ) <=> std::tie ( other.getData ( ), other.getString ( ) );
142 }
143
151 bool operator == ( const SuffixArray & other ) const {
152 return std::tie ( getData ( ), getString ( ) ) == std::tie ( other.getData ( ), other.getString ( ) );
153 }
154
163 friend ext::ostream & operator << ( ext::ostream & out, const SuffixArray & instance ) {
164 return out << "(SuffixArray " << instance.m_data << ", " << instance.m_string << ")";
165 }
166};
167
168} /* namespace stringology */
169
170} /* namespace indexes */
171
172namespace indexes {
173
174namespace stringology {
175
176template < class SymbolType >
177SuffixArray < SymbolType >::SuffixArray ( ext::vector < unsigned > data, string::LinearString < SymbolType > string ) : m_data ( std::move ( data ) ), m_string ( std::move ( string ) ) {
178}
179
180template < class SymbolType >
182 return m_data;
183}
184
185template < class SymbolType >
187 return std::move ( m_data );
188}
189
190template < class SymbolType >
192 return m_string;
193}
194
195template < class SymbolType >
197 return std::move ( m_string );
198}
199
200template < class SymbolType >
202 this->m_data = std::move ( data );
203}
204
205} /* namespace stringology */
206
207} /* namespace indexes */
208
209namespace core {
210
216template < class SymbolType >
217struct normalize < indexes::stringology::SuffixArray < SymbolType > > {
219 string::LinearString < DefaultSymbolType > string = normalize < string::LinearString < SymbolType > >::eval ( std::move ( value ).getString ( ) );
220
221 return indexes::stringology::SuffixArray < > ( std::move ( value ).getData ( ), std::move ( string ) );
222 }
223};
224
225} /* namespace core */
226
Definition: ostream.h:14
Definition: set.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Suffix array string index. Linear representation of all suffixes ordered lexicographically....
Definition: SuffixArray.h:51
SuffixArray(ext::vector< unsigned > data, string::LinearString< SymbolType > string)
Definition: SuffixArray.h:177
void setData(ext::vector< unsigned > data)
Definition: SuffixArray.h:201
const ext::vector< unsigned > & getData() const &
Definition: SuffixArray.h:181
bool operator==(const SuffixArray &other) const
Definition: SuffixArray.h:151
ext::set< SymbolType > && getAlphabet() &&
Definition: SuffixArray.h:113
auto operator<=>(const SuffixArray &other) const
Definition: SuffixArray.h:140
const string::LinearString< SymbolType > & getString() const &
Definition: SuffixArray.h:191
bool removeSymbolFromAlphabet(const SymbolType &symbol)
Definition: SuffixArray.h:129
friend ext::ostream & operator<<(ext::ostream &out, const SuffixArray &instance)
Definition: SuffixArray.h:163
const ext::set< SymbolType > & getAlphabet() const &
Definition: SuffixArray.h:104
Linear string.
Definition: LinearString.h:57
const ext::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
Definition: CompressedBitParallelTreeIndex.h:40
Definition: RandomStringFactory.cpp:12
Definition: ArithmeticCompression.h:18
static indexes::stringology::SuffixArray< > eval(indexes::stringology::SuffixArray< SymbolType > &&value)
Definition: SuffixArray.h:218
Definition: normalize.hpp:13