Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
PositionHeapFactors.h
Go to the documentation of this file.
1
6#pragma once
7
9#include <string/LinearString.h>
10#include <global/GlobalData.h>
11
12namespace stringology {
13
14namespace query {
15
25 template < class SymbolType >
26 static void accumulateResult ( const ext::trie < SymbolType, unsigned > & trie, ext::set < unsigned > & res, unsigned indexedStringSize ) {
27 res.insert ( indexedStringSize - trie.getData ( ) );
28
29 for ( const std::pair < const SymbolType, ext::trie < SymbolType, unsigned > > & child : trie.getChildren ( ) ) {
30 accumulateResult ( child.second, res, indexedStringSize );
31 }
32 }
33
34 template < class SymbolType >
35 static bool checkOcc ( const string::LinearString < SymbolType > & needle, unsigned validSymbols, const ext::vector < SymbolType > & haystack, unsigned haystackPosition ) {
36 if ( haystackPosition + needle.getContent ( ).size ( ) > haystack.size ( ) )
37 return false;
38
39 for ( unsigned i = validSymbols; i < needle.getContent ( ).size ( ); i++ ) {
40 if ( needle.getContent ( ) [ i ] != haystack [ haystackPosition + i ] )
41 return false;
42 }
43 return true;
44 }
45
46public:
53 template < class SymbolType >
55
56};
57
58template < class SymbolType >
61
62 const ext::trie < SymbolType, unsigned > * node = & positionHeap.getRoot ( );
63 unsigned depth = 0;
64 unsigned indexedStringSize = positionHeap.getString ( ).getContent ( ).size ( );
65
66 for ( const SymbolType & symbol : string.getContent ( ) ) {
67
69 common::Streams::log << "on path possible occ (raw, string index): (" << node->getData ( ) << ", " << indexedStringSize - node->getData ( ) << ")" << std::endl;
70
71 if ( checkOcc ( string, depth, positionHeap.getString ( ).getContent ( ), indexedStringSize - node->getData ( ) ) )
72 res.insert ( indexedStringSize - node->getData ( ) );
73
74 auto iter = node->getChildren ( ).find ( symbol );
75 if ( iter == node->getChildren ( ).end ( ) )
76 return res;
77
78 depth++;
79 node = & iter->second;
80 }
81
82 accumulateResult ( * node, res, indexedStringSize );
83 return res;
84}
85
86} /* namespace query */
87
88} /* namespace stringology */
89
static bool verbose
Verbose flag. Some algorithms print additional runtime information about internal datastructures or t...
Definition: GlobalData.h:24
static ext::reference_wrapper< ext::ostream > log
Standard loging stream. Mapped to descriptor 4.
Definition: GlobalData.h:78
Definition: set.hpp:44
Class introducing a trie with interface trying to be close to the interface of standard library conta...
Definition: trie.hpp:47
ext::map< Key, trie > & getChildren()
Getter of children of the root node.
Definition: trie.hpp:115
Value & getData()
Getter of the value in the root node.
Definition: trie.hpp:95
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Position heap string index. Tree like representation of all suffixes. The suffixes are themselves rep...
Definition: PositionHeap.h:56
const ext::trie< SymbolType, unsigned > & getRoot() const &
Definition: PositionHeap.h:203
const string::LinearString< SymbolType > & getString() const &
Definition: PositionHeap.h:213
Linear string.
Definition: LinearString.h:57
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: PositionHeapFactors.h:24
static ext::set< unsigned > query(const indexes::stringology::PositionHeap< SymbolType > &positionHeap, const string::LinearString< SymbolType > &string)
Definition: PositionHeapFactors.h:59
int i
Definition: AllEpsilonClosure.h:118
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
Definition: Node.cpp:11
Definition: ArithmeticCompression.h:18