Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
CompressedBitParallelTreeIndex.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
32
33#include <core/components.hpp>
35
37
39
40namespace indexes {
41
42namespace arbology {
43
44class GeneralAlphabet;
45
54template < class SymbolType = DefaultSymbolType >
55class CompressedBitParallelTreeIndex final : public core::Components < CompressedBitParallelTreeIndex < SymbolType >, ext::set < common::ranked_symbol < SymbolType > >, component::Set, GeneralAlphabet > {
60
64 ext::vector < int > m_jumpTable;
65
66public:
75
82
89
95 const ext::vector < int > & getJumps ( ) const &;
96
103
110
117 return this->template accessComponent < GeneralAlphabet > ( ).get ( );
118 }
119
126 return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) );
127 }
128
136
143 return this->template accessComponent < GeneralAlphabet > ( ).remove ( symbol );
144 }
145
153 auto operator <=> ( const CompressedBitParallelTreeIndex & other ) const {
154 return std::tie ( getData ( ), getAlphabet ( ), getJumps ( ) ) <=> std::tie ( other.getData ( ), other.getAlphabet ( ), other.getJumps ( ) );
155 }
156
164 bool operator == ( const CompressedBitParallelTreeIndex & other ) const {
165 return std::tie ( getData ( ), getAlphabet ( ), getJumps ( ) ) == std::tie ( other.getData ( ), other.getAlphabet ( ), other.getJumps ( ) );
166 }
167
177 return out << "(CompressedBitParallelTreeIndex " << instance.m_vectors << ", " << instance.m_jumpTable << ")";
178 }
179};
180
181} /* namespace arbology */
182
183} /* namespace indexes */
184
185namespace indexes {
186
187namespace arbology {
188
189template < class SymbolType >
191}
192
193template < class SymbolType >
195 return m_vectors;
196}
197
198template < class SymbolType >
200 return std::move ( m_vectors );
201}
202
203template < class SymbolType >
205 return m_jumpTable;
206}
207
208template < class SymbolType >
210 return std::move ( m_jumpTable );
211}
212
213template < class SymbolType >
216
217 unsigned index = 0;
218
219 do {
220 for ( const std::pair < const common::ranked_symbol < SymbolType >, common::SparseBoolVector > & compressedBitVector : m_vectors )
221 if ( compressedBitVector.second.size ( ) > index && compressedBitVector.second [ index ] ) {
222 res.push_back ( compressedBitVector.first );
223 continue;
224 }
225
226 } while ( res.size ( ) == index ++ + 1 );
227
228 return res;
229}
230
231template < class SymbolType >
233 this->m_vectors [ symbol ] = std::move ( data );
234}
235
236} /* namespace arbology */
237
238} /* namespace indexes */
239
240namespace core {
241
247template < class SymbolType >
248class SetConstraint < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType >, common::ranked_symbol < SymbolType >, indexes::arbology::GeneralAlphabet > {
249public:
260
261 return content.find ( symbol ) != content.end ( );
262 }
263
273 return true;
274 }
275
283 }
284
285};
286
292template < class SymbolType >
293struct normalize < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType > > {
296
298 for ( std::pair < common::ranked_symbol < SymbolType >, common::SparseBoolVector > && vector : ext::make_mover ( std::move ( value ).getData ( ) ) )
299 vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) );
300
301 return indexes::arbology::CompressedBitParallelTreeIndex < > ( std::move ( alphabet ), std::move ( vectors ), std::move ( value ).getJumps ( ) );
302 }
303};
304
305} /* namespace core */
306
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 void valid(const indexes::arbology::CompressedBitParallelTreeIndex< SymbolType > &, const common::ranked_symbol< SymbolType > &)
Definition: CompressedBitParallelTreeIndex.h:282
static bool available(const indexes::arbology::CompressedBitParallelTreeIndex< SymbolType > &, const common::ranked_symbol< SymbolType > &)
Definition: CompressedBitParallelTreeIndex.h:272
static bool used(const indexes::arbology::CompressedBitParallelTreeIndex< common::ranked_symbol< SymbolType > > &index, const common::ranked_symbol< SymbolType > &symbol)
Definition: CompressedBitParallelTreeIndex.h:258
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 tree index. Stores a bit vector for each symbol of the alphabet....
Definition: CompressedBitParallelTreeIndex.h:55
CompressedBitParallelTreeIndex(ext::set< common::ranked_symbol< SymbolType > > alphabet, ext::map< common::ranked_symbol< SymbolType >, common::SparseBoolVector > vectors, ext::vector< int > jumpTable)
Definition: CompressedBitParallelTreeIndex.h:190
bool operator==(const CompressedBitParallelTreeIndex &other) const
Definition: CompressedBitParallelTreeIndex.h:164
const ext::map< common::ranked_symbol< SymbolType >, common::SparseBoolVector > & getData() const &
Definition: CompressedBitParallelTreeIndex.h:194
friend ext::ostream & operator<<(ext::ostream &out, const CompressedBitParallelTreeIndex &instance)
Definition: CompressedBitParallelTreeIndex.h:176
bool removeSymbolFromAlphabet(const common::ranked_symbol< SymbolType > &symbol)
Definition: CompressedBitParallelTreeIndex.h:142
auto operator<=>(const CompressedBitParallelTreeIndex &other) const
Definition: CompressedBitParallelTreeIndex.h:153
ext::set< common::ranked_symbol< SymbolType > > && getAlphabet() &&
Definition: CompressedBitParallelTreeIndex.h:125
void setCompressedBitVectorForSymbol(common::ranked_symbol< SymbolType > symbol, common::SparseBoolVector data)
Definition: CompressedBitParallelTreeIndex.h:232
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: CompressedBitParallelTreeIndex.h:116
ext::vector< common::ranked_symbol< SymbolType > > getString() const
Definition: CompressedBitParallelTreeIndex.h:214
const ext::vector< int > & getJumps() const &
Definition: CompressedBitParallelTreeIndex.h:204
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::CompressedBitParallelTreeIndex< > eval(indexes::arbology::CompressedBitParallelTreeIndex< SymbolType > &&value)
Definition: CompressedBitParallelTreeIndex.h:294
Definition: normalize.hpp:13