Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
WideBNDMOccurrences.h
Go to the documentation of this file.
1
6#pragma once
7
9#include <string/LinearString.h>
10#include <global/GlobalData.h>
11
12#include <ext/foreach>
13
14namespace stringology {
15
16namespace query {
17
24public:
31 template < class SymbolType >
33
34};
35
36template < class SymbolType >
38
40
41 size_t patternLength = pattern.getData ( ).begin ( )->second.size ( );
42 size_t subjectLength = subject.getContent ( ).size ( );
43 size_t posInSubject = 0;
44
45 ext::vector < bool > currentBitmask;
46 currentBitmask.resize ( patternLength );
47
48 while ( posInSubject + patternLength <= subjectLength ) {
49 size_t posInPattern = patternLength;
50 size_t lastPosOfFactor = patternLength;
51
52 // Set the bitmask to all ones
53 ext::fill ( currentBitmask );
54
55 while ( posInPattern > 0 && ext::any ( currentBitmask ) ) {
56 typename ext::map < SymbolType, ext::vector < bool > >::const_iterator symbolVectorIter = pattern.getData ( ).find ( subject.getContent ( ).at ( posInSubject + posInPattern - 1 ) );
57 if ( symbolVectorIter == pattern.getData ( ).end ( ) )
58 break;
59
60 currentBitmask &= symbolVectorIter->second;
61 posInPattern--;
62
63 // Test whether the most significant bit is set
64 if ( currentBitmask [ patternLength - 1 ] ) {
65 // and we didn't process all symbols of the pattern
66 if ( posInPattern > 0 )
67 lastPosOfFactor = posInPattern;
68 else /* posInPattern == 0 */
69 // Yay, there is match!!!
70 occ.insert ( posInSubject );
71 }
72
73 currentBitmask <<= 1;
74 }
75
76 posInSubject += lastPosOfFactor;
77 }
78
79 return occ;
80}
81
82} /* namespace query */
83
84} /* namespace stringology */
85
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
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::map< SymbolType, ext::vector< bool > > & getData() const &
Definition: BitParallelIndex.h:170
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: WideBNDMOccurrences.h:23
static ext::set< unsigned > query(const indexes::stringology::BitParallelIndex< SymbolType > &pattern, const string::LinearString< SymbolType > &subject)
Definition: WideBNDMOccurrences.h:37
void fill(ext::vector< bool, Ts ... > &v)
Sets all bits in the vector of booleans.
Definition: vector.hpp:852
bool any(const ext::vector< bool, Ts ... > &v)
Tests the vector of booleans whether at least one bit inside is set.
Definition: vector.hpp:820
Definition: ArithmeticCompression.h:18