Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NonlinearCompressedBitParallelTreeIndex.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 <alib/set>
27#include <alib/map>
28#include <alib/string>
29
31
32#include <core/components.hpp>
34
36
38
39namespace indexes {
40
41namespace arbology {
42
43class GeneralAlphabet;
44
54template < class SymbolType = DefaultSymbolType >
55class NonlinearCompressedBitParallelTreeIndex final : public core::Components < NonlinearCompressedBitParallelTreeIndex < SymbolType >, ext::set < common::ranked_symbol < SymbolType > >, component::Set, GeneralAlphabet > {
60
64 ext::vector < int > m_jumpTable;
65
70
71public:
81
88
95
101 const ext::vector < int > & getJumps ( ) const &;
102
109
115 const ext::vector < unsigned > & getRepeats ( ) const &;
116
123
130
137 return this->template accessComponent < GeneralAlphabet > ( ).get ( );
138 }
139
146 return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) );
147 }
148
156
163 return this->template accessComponent < GeneralAlphabet > ( ).remove ( symbol );
164 }
165
174 return std::tie ( getData ( ), getAlphabet ( ), getJumps ( ), getRepeats ( ) ) <=> std::tie ( other.getData ( ), other.getAlphabet ( ), other.getJumps ( ), getRepeats ( ) );
175 }
176
185 return std::tie ( getData ( ), getAlphabet ( ), getJumps ( ), getRepeats ( ) ) == std::tie ( other.getData ( ), other.getAlphabet ( ), other.getJumps ( ), getRepeats ( ) );
186 }
187
197 return out << "(NonlinearCompressedBitParallelTreeIndex " << instance.m_vectors << ", " << instance.m_jumpTable << ")";
198 }
199};
200
201} /* namespace arbology */
202
203} /* namespace indexes */
204
205namespace indexes {
206
207namespace arbology {
208
209template < class SymbolType >
211}
212
213template < class SymbolType >
215 return m_vectors;
216}
217
218template < class SymbolType >
220 return std::move ( m_vectors );
221}
222
223template < class SymbolType >
225 return m_jumpTable;
226}
227
228template < class SymbolType >
230 return std::move ( m_jumpTable );
231}
232
233template < class SymbolType >
235 return m_repeats;
236}
237
238template < class SymbolType >
240 return std::move ( m_repeats );
241}
242
243template < class SymbolType >
246
247 unsigned index = 0;
248
249 do {
250 for ( const std::pair < const common::ranked_symbol < SymbolType >, common::SparseBoolVector > & nonlinearcompressedBitVector : m_vectors )
251 if ( nonlinearcompressedBitVector.second.size ( ) > index && nonlinearcompressedBitVector.second [ index ] ) {
252 res.push_back ( nonlinearcompressedBitVector.first );
253 continue;
254 }
255
256 } while ( res.size ( ) == index ++ + 1 );
257
258 return res;
259}
260
261template < class SymbolType >
263 this->m_vectors [ symbol ] = std::move ( data );
264}
265
266} /* namespace arbology */
267
268} /* namespace indexes */
269
270namespace core {
271
277template < class SymbolType >
278class SetConstraint < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType >, common::ranked_symbol < SymbolType >, indexes::arbology::GeneralAlphabet > {
279public:
290
291 return content.find ( symbol ) != content.end ( );
292 }
293
303 return true;
304 }
305
313 }
314
315};
316
322template < class SymbolType >
323struct normalize < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType > > {
326
328 for ( std::pair < common::ranked_symbol < SymbolType >, common::SparseBoolVector > && vector : ext::make_mover ( std::move ( value ).getData ( ) ) )
329 vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) );
330
331 return indexes::arbology::NonlinearCompressedBitParallelTreeIndex < > ( std::move ( alphabet ), std::move ( vectors ), std::move ( value ).getJumps ( ), std::move ( value ).getRepeats ( ) );
332 }
333};
334
335} /* namespace core */
336
static common::ranked_symbol< DefaultSymbolType > normalizeRankedSymbol(common::ranked_symbol< SymbolType > &&symbol)
Definition: SymbolNormalize.h:81
static ext::set< common::ranked_symbol< DefaultSymbolType > > normalizeRankedAlphabet(ext::set< common::ranked_symbol< SymbolType > > &&symbols)
Definition: SymbolNormalize.h:59
Definition: SparseBoolVector.hpp:27
Definition: ranked_symbol.hpp:20
Definition: components.hpp:181
static bool available(const indexes::arbology::NonlinearCompressedBitParallelTreeIndex< SymbolType > &, const common::ranked_symbol< SymbolType > &)
Definition: NonlinearCompressedBitParallelTreeIndex.h:302
static void valid(const indexes::arbology::NonlinearCompressedBitParallelTreeIndex< SymbolType > &, const common::ranked_symbol< SymbolType > &)
Definition: NonlinearCompressedBitParallelTreeIndex.h:312
static bool used(const indexes::arbology::NonlinearCompressedBitParallelTreeIndex< SymbolType > &index, const common::ranked_symbol< SymbolType > &symbol)
Definition: NonlinearCompressedBitParallelTreeIndex.h:288
Definition: setComponents.hpp:26
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
auto end() &
Inherited behavior of end for non-const instance.
Definition: map.hpp:215
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
Compressed bit parallel nonlinear tree index. Stores a bit vector for each symbol of the alphabet....
Definition: NonlinearCompressedBitParallelTreeIndex.h:55
bool removeSymbolFromAlphabet(const common::ranked_symbol< SymbolType > &symbol)
Definition: NonlinearCompressedBitParallelTreeIndex.h:162
const ext::vector< int > & getJumps() const &
Definition: NonlinearCompressedBitParallelTreeIndex.h:224
friend ext::ostream & operator<<(ext::ostream &out, const NonlinearCompressedBitParallelTreeIndex &instance)
Definition: NonlinearCompressedBitParallelTreeIndex.h:196
const ext::map< common::ranked_symbol< SymbolType >, common::SparseBoolVector > & getData() const &
Definition: NonlinearCompressedBitParallelTreeIndex.h:214
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: NonlinearCompressedBitParallelTreeIndex.h:136
ext::set< common::ranked_symbol< SymbolType > > && getAlphabet() &&
Definition: NonlinearCompressedBitParallelTreeIndex.h:145
bool operator==(const NonlinearCompressedBitParallelTreeIndex &other) const
Definition: NonlinearCompressedBitParallelTreeIndex.h:184
auto operator<=>(const NonlinearCompressedBitParallelTreeIndex &other) const
Definition: NonlinearCompressedBitParallelTreeIndex.h:173
const ext::vector< unsigned > & getRepeats() const &
Definition: NonlinearCompressedBitParallelTreeIndex.h:234
NonlinearCompressedBitParallelTreeIndex(ext::set< common::ranked_symbol< SymbolType > > alphabet, ext::map< common::ranked_symbol< SymbolType >, common::SparseBoolVector > vectors, ext::vector< int > jumpTable, ext::vector< unsigned > repeats)
Definition: NonlinearCompressedBitParallelTreeIndex.h:210
void setNonlinearCompressedBitVectorForSymbol(common::ranked_symbol< SymbolType > symbol, common::SparseBoolVector data)
Definition: NonlinearCompressedBitParallelTreeIndex.h:262
ext::vector< common::ranked_symbol< SymbolType > > getString() const
Definition: NonlinearCompressedBitParallelTreeIndex.h:244
Definition: BarSymbol.cpp:12
Definition: BoyerMooreHorspool.h:22
return res
Definition: MinimizeByPartitioning.h:145
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
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: CompressedBitParallelTreeIndex.h:40
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
static indexes::arbology::NonlinearCompressedBitParallelTreeIndex< > eval(indexes::arbology::NonlinearCompressedBitParallelTreeIndex< SymbolType > &&value)
Definition: NonlinearCompressedBitParallelTreeIndex.h:324
Definition: normalize.hpp:13