Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
BitSetIndex.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/map>
29#include <alib/set>
30#include <alib/string>
31#include <alib/bitset>
32
34
35#include <core/components.hpp>
37
39
40#include <string/LinearString.h>
41
42namespace indexes {
43
44namespace stringology {
45
46class GeneralAlphabet;
47
53template < class SymbolType = DefaultSymbolType, size_t BitmaskBitCount = 64 >
54class BitSetIndex final : public core::Components < BitSetIndex < SymbolType >, ext::set < SymbolType >, component::Set, GeneralAlphabet > {
59
64
65public:
73
80
87
94
101
108 return m_string.getAlphabet ( );
109 }
110
117 return m_string.getAlphabet ( );
118 }
119
127
133 bool removeSymbolFromAlphabet ( const SymbolType & symbol ) {
134 return m_string.removeSymbol ( symbol );
135 }
136
144 auto operator <=> ( const BitSetIndex & other ) const {
145 return std::tie ( getData ( ), getAlphabet ( ) ) <=> std::tie ( other.getData ( ), other.getAlphabet ( ) );
146 }
147
155 bool operator == ( const BitSetIndex & other ) const {
156 return std::tie ( getData ( ), getAlphabet ( ) ) == std::tie ( other.getData ( ), other.getAlphabet ( ) );
157 }
158
167 friend ext::ostream & operator << ( ext::ostream & out, const BitSetIndex & instance ) {
168 return out << "(BitSetIndex " << instance.m_vectors << ")";
169 }
170};
171
172} /* namespace stringology */
173
174} /* namespace indexes */
175
176namespace indexes {
177
178namespace stringology {
179
180template < class SymbolType, size_t BitmaskBitCount >
182}
183
184template < class SymbolType, size_t BitmaskBitCount >
186 return m_vectors;
187}
188
189template < class SymbolType, size_t BitmaskBitCount >
191 return std::move ( m_vectors );
192}
193
194template < class SymbolType, size_t BitmaskBitCount >
196 return m_string;
197}
198
199template < class SymbolType, size_t BitmaskBitCount >
201 return std::move ( m_string );
202}
203
204template < class SymbolType, size_t BitmaskBitCount >
206 this->m_vectors [ symbol ] = std::move ( data );
207}
208
209} /* namespace stringology */
210
211} /* namespace indexes */
212
213namespace core {
214
215template < class SymbolType, size_t BitmaskBitCount >
216struct normalize < indexes::stringology::BitSetIndex < SymbolType, BitmaskBitCount > > {
219 for ( std::pair < SymbolType, ext::bitset < BitmaskBitCount > > && vector : ext::make_mover ( std::move ( value ).getData ( ) ) )
220 vectors.insert ( std::make_pair ( alphabet::SymbolNormalize::normalizeSymbol ( std::move ( vector.first ) ), std::move ( vector.second ) ) );
221
222 string::LinearString < DefaultSymbolType > string = normalize < string::LinearString < SymbolType > >::eval ( std::move ( value ).getString ( ) );
223
224 return indexes::stringology::BitSetIndex < DefaultSymbolType, BitmaskBitCount > ( std::move ( vectors ), std::move ( string ) );
225 }
226};
227
228} /* namespace core */
229
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Definition: components.hpp:181
Class extending the bitset class from the standard library. Original reason is to allow printing of t...
Definition: bitset.hpp:42
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
Definition: ostream.h:14
Definition: set.hpp:44
Bit set string index. Stores a bit set for each symbol of the alphabet. The bit set of symbol a conta...
Definition: BitSetIndex.h:54
bool removeSymbolFromAlphabet(const SymbolType &symbol)
Definition: BitSetIndex.h:133
bool operator==(const BitSetIndex &other) const
Definition: BitSetIndex.h:155
const ext::map< SymbolType, ext::bitset< BitmaskBitCount > > & getData() const &
Definition: BitSetIndex.h:185
const ext::set< SymbolType > & getAlphabet() const &
Definition: BitSetIndex.h:107
friend ext::ostream & operator<<(ext::ostream &out, const BitSetIndex &instance)
Definition: BitSetIndex.h:167
auto operator<=>(const BitSetIndex &other) const
Definition: BitSetIndex.h:144
BitSetIndex(ext::map< SymbolType, ext::bitset< BitmaskBitCount > > vectors, string::LinearString< SymbolType > string)
Definition: BitSetIndex.h:181
ext::set< SymbolType > && getAlphabet() &&
Definition: BitSetIndex.h:116
const string::LinearString< SymbolType > & getString() const &
Definition: BitSetIndex.h:195
void setBitVectorForSymbol(SymbolType symbol, ext::bitset< BitmaskBitCount > data)
Definition: BitSetIndex.h:205
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
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
Definition: RandomStringFactory.cpp:12
Definition: ArithmeticCompression.h:18
static indexes::stringology::BitSetIndex< DefaultSymbolType, BitmaskBitCount > eval(indexes::stringology::BitSetIndex< SymbolType, BitmaskBitCount > &&value)
Definition: BitSetIndex.h:217
Definition: normalize.hpp:13