Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
BitParallelIndex.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
36#include <core/normalize.hpp>
38
39namespace indexes {
40
41namespace stringology {
42
43class GeneralAlphabet;
44
50template < class SymbolType = DefaultSymbolType >
51class BitParallelIndex final : public core::Components < BitParallelIndex < SymbolType >, ext::set < SymbolType >, component::Set, GeneralAlphabet > {
56
57public:
65
72
79
86
93 return this->template accessComponent < GeneralAlphabet > ( ).get ( );
94 }
95
102 return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) );
103 }
104
112
118 bool removeSymbolFromAlphabet ( const SymbolType & symbol ) {
119 return this->template accessComponent < GeneralAlphabet > ( ).remove ( symbol );
120 }
121
129 auto operator <=> ( const BitParallelIndex & other ) const {
130 return std::tie ( getData ( ), getAlphabet ( ) ) <=> std::tie ( other.getData ( ), other.getAlphabet ( ) );
131 }
132
140 bool operator == ( const BitParallelIndex & other ) const {
141 return std::tie ( getData ( ), getAlphabet ( ) ) == std::tie ( other.getData ( ), other.getAlphabet ( ) );
142 }
143
152 friend ext::ostream & operator << ( ext::ostream & out, const BitParallelIndex & instance ) {
153 return out << "(BitParallelIndex " << instance.m_vectors << ")";
154 }
155};
156
157} /* namespace stringology */
158
159} /* namespace indexes */
160
161namespace indexes {
162
163namespace stringology {
164
165template < class SymbolType >
167}
168
169template < class SymbolType >
171 return m_vectors;
172}
173
174template < class SymbolType >
176 return std::move ( m_vectors );
177}
178
179template < class SymbolType >
182
183 unsigned index = 0;
184 do {
185 for ( const std::pair < const SymbolType, ext::vector < bool > > & bitVector : m_vectors )
186 if ( bitVector.second.size ( ) > index && bitVector.second [ index ] ) {
187 res.push_back ( bitVector.first );
188 continue;
189 }
190
191 } while ( res.size ( ) == index ++ + 1 );
192
193 return res;
194}
195
196template < class SymbolType >
198 this->m_vectors [ symbol ] = std::move ( data );
199}
200
201} /* namespace stringology */
202
203} /* namespace indexes */
204
205namespace core {
206
212template < class SymbolType >
213class SetConstraint < indexes::stringology::BitParallelIndex < SymbolType >, SymbolType, indexes::stringology::GeneralAlphabet > {
214public:
223 static bool used ( const indexes::stringology::BitParallelIndex < SymbolType > & index, const SymbolType & symbol ) {
224 const ext::map < SymbolType, ext::vector < bool > > & content = index.getData ( );
225 return content.find( symbol ) != content.end();
226 }
227
237 return true;
238 }
239
247 }
248};
249
255template < class SymbolType >
256struct normalize < indexes::stringology::BitParallelIndex < SymbolType > > {
259
261 for ( std::pair < SymbolType, ext::vector < bool > > && vector : ext::make_mover ( std::move ( value ).getData ( ) ) )
262 vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) );
263
264 return indexes::stringology::BitParallelIndex < > ( std::move ( alphabet ), std::move ( vectors ) );
265 }
266};
267
268} /* namespace core */
269
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Definition: components.hpp:181
static bool available(const indexes::stringology::BitParallelIndex< SymbolType > &, const SymbolType &)
Definition: BitParallelIndex.h:236
static void valid(const indexes::stringology::BitParallelIndex< SymbolType > &, const SymbolType &)
Definition: BitParallelIndex.h:246
static bool used(const indexes::stringology::BitParallelIndex< SymbolType > &index, const SymbolType &symbol)
Definition: BitParallelIndex.h:223
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
Bit parallel string index. Stores a bit vector for each symbol of the alphabet. The bit vector of sym...
Definition: BitParallelIndex.h:51
const ext::set< SymbolType > & getAlphabet() const &
Definition: BitParallelIndex.h:92
friend ext::ostream & operator<<(ext::ostream &out, const BitParallelIndex &instance)
Definition: BitParallelIndex.h:152
ext::vector< SymbolType > getString() const
Definition: BitParallelIndex.h:180
const ext::map< SymbolType, ext::vector< bool > > & getData() const &
Definition: BitParallelIndex.h:170
bool removeSymbolFromAlphabet(const SymbolType &symbol)
Definition: BitParallelIndex.h:118
BitParallelIndex(ext::set< SymbolType > alphabet, ext::map< SymbolType, ext::vector< bool > > vectors)
Definition: BitParallelIndex.h:166
bool operator==(const BitParallelIndex &other) const
Definition: BitParallelIndex.h:140
ext::set< SymbolType > && getAlphabet() &&
Definition: BitParallelIndex.h:101
void setBitVectorForSymbol(SymbolType symbol, ext::vector< bool > data)
Definition: BitParallelIndex.h:197
auto operator<=>(const BitParallelIndex &other) const
Definition: BitParallelIndex.h:129
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::BitParallelIndex< > eval(indexes::stringology::BitParallelIndex< SymbolType > &&value)
Definition: BitParallelIndex.h:257
Definition: normalize.hpp:13