Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
CompressedBitParallelIndex.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
28#include <alib/set>
29#include <alib/string>
30
32
33#include <core/components.hpp>
35
37
38#include <core/normalize.hpp>
40
41namespace indexes {
42
43namespace stringology {
44
45class GeneralAlphabet;
46
52template < class SymbolType = DefaultSymbolType >
53class CompressedBitParallelIndex final : public core::Components < CompressedBitParallelIndex < SymbolType >, ext::set < SymbolType >, component::Set, GeneralAlphabet > {
58
59public:
67
74
81
88
95 return this->template accessComponent < GeneralAlphabet > ( ).get ( );
96 }
97
104 return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) );
105 }
106
114
120 bool removeSymbolFromAlphabet ( const SymbolType & symbol ) {
121 return this->template accessComponent < GeneralAlphabet > ( ).remove ( symbol );
122 }
123
131 auto operator <=> ( const CompressedBitParallelIndex & other ) const {
132 return std::tie ( getData ( ), getAlphabet ( ) ) <=> std::tie ( other.getData ( ), other.getAlphabet ( ) );
133 }
134
142 auto operator == ( const CompressedBitParallelIndex & other ) const {
143 return std::tie ( getData ( ), getAlphabet ( ) ) == std::tie ( other.getData ( ), other.getAlphabet ( ) );
144 }
145
155 return out << "(CompressedBitParallelIndex " << instance.m_vectors << ")";
156 }
157};
158
159} /* namespace stringology */
160
161} /* namespace indexes */
162
163namespace indexes {
164
165namespace stringology {
166
167template < class SymbolType >
169}
170
171template < class SymbolType >
173 return m_vectors;
174}
175
176template < class SymbolType >
178 return std::move ( m_vectors );
179}
180
181template < class SymbolType >
184
185 unsigned index = 0;
186 do {
187 for ( const std::pair < const SymbolType, common::SparseBoolVector > & compressedBitVector : m_vectors )
188 if ( compressedBitVector.second.size ( ) > index && compressedBitVector.second [ index ] ) {
189 res.push_back ( compressedBitVector.first );
190 continue;
191 }
192
193 } while ( res.size ( ) == index ++ + 1 );
194
195 return res;
196}
197
198template < class SymbolType >
200 this->m_vectors [ symbol ] = std::move ( data );
201}
202
203} /* namespace stringology */
204
205} /* namespace indexes */
206
207namespace core {
208
214template < class SymbolType >
215class SetConstraint < indexes::stringology::CompressedBitParallelIndex < SymbolType >, SymbolType, indexes::stringology::GeneralAlphabet > {
216public:
227 return content.find( symbol ) != content.end();
228 }
229
239 return true;
240 }
241
249 }
250};
251
257template < class SymbolType >
258struct normalize < indexes::stringology::CompressedBitParallelIndex < SymbolType > > {
261
263 for ( std::pair < SymbolType, common::SparseBoolVector > && vector : ext::make_mover ( std::move ( value ).getData ( ) ) )
264 vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) );
265
266 return indexes::stringology::CompressedBitParallelIndex < > ( std::move ( alphabet ), std::move ( vectors ) );
267 }
268};
269
270} /* namespace core */
271
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Definition: SparseBoolVector.hpp:27
Definition: components.hpp:181
static void valid(const indexes::stringology::CompressedBitParallelIndex< SymbolType > &, const SymbolType &)
Definition: CompressedBitParallelIndex.h:248
static bool available(const indexes::stringology::CompressedBitParallelIndex< SymbolType > &, const SymbolType &)
Definition: CompressedBitParallelIndex.h:238
static bool used(const indexes::stringology::CompressedBitParallelIndex< SymbolType > &index, const SymbolType &symbol)
Definition: CompressedBitParallelIndex.h:225
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 string index. Stores a bit vector for each symbol of the alphabet....
Definition: CompressedBitParallelIndex.h:53
CompressedBitParallelIndex(ext::set< SymbolType > alphabet, ext::map< SymbolType, common::SparseBoolVector > vectors)
Definition: CompressedBitParallelIndex.h:168
const ext::set< SymbolType > & getAlphabet() const &
Definition: CompressedBitParallelIndex.h:94
ext::set< SymbolType > && getAlphabet() &&
Definition: CompressedBitParallelIndex.h:103
ext::vector< SymbolType > getString() const
Definition: CompressedBitParallelIndex.h:182
auto operator==(const CompressedBitParallelIndex &other) const
Definition: CompressedBitParallelIndex.h:142
void setCompressedBitVectorForSymbol(SymbolType symbol, common::SparseBoolVector data)
Definition: CompressedBitParallelIndex.h:199
bool removeSymbolFromAlphabet(const SymbolType &symbol)
Definition: CompressedBitParallelIndex.h:120
const ext::map< SymbolType, common::SparseBoolVector > & getData() const &
Definition: CompressedBitParallelIndex.h:172
friend ext::ostream & operator<<(ext::ostream &out, const CompressedBitParallelIndex &instance)
Definition: CompressedBitParallelIndex.h:154
auto operator<=>(const CompressedBitParallelIndex &other) const
Definition: CompressedBitParallelIndex.h:131
Definition: BarSymbol.cpp:12
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
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
Definition: ArithmeticCompression.h:18
static indexes::stringology::CompressedBitParallelIndex< > eval(indexes::stringology::CompressedBitParallelIndex< SymbolType > &&value)
Definition: CompressedBitParallelIndex.h:259
Definition: normalize.hpp:13