Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
DeadZoneUsingBadCharacterShiftAndBorderArray.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/set>
9#include <alib/vector>
10#include <alib/map>
11
13
18
23
24namespace arbology {
25
26namespace exact {
27
32public:
37 template < class SymbolType >
39 template < class SymbolType >
41 template < class SymbolType >
42 static void match_rec ( ext::set < unsigned > & occ, const tree::PrefixRankedBarTree < SymbolType > & subject, const tree::PrefixRankedBarPattern < SymbolType > & pattern, ext::vector < size_t > & fba, ext::map < common::ranked_symbol < SymbolType >, size_t > & bbcs, ext::vector < int > & subjectSubtreeJumpTable, int low, int high );
43
44 template < class SymbolType >
46 template < class SymbolType >
48 template < class SymbolType >
49 static void match_rec ( ext::set < unsigned > & occ, const tree::PrefixRankedTree < SymbolType > & subject, const tree::PrefixRankedPattern < SymbolType > & pattern, ext::vector < size_t > & fba, ext::map < common::ranked_symbol < SymbolType >, size_t > & bbcs, ext::vector < int > & subjectSubtreeJumpTable, int low, int high );
50
51};
52
53template < class SymbolType >
55 return match ( subject, tree::PrefixRankedBarPattern < SymbolType > ( pattern ) );
56}
57
58template < class SymbolType >
61 ext::map < common::ranked_symbol < SymbolType >, size_t > bbcs = tree::properties::ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
63 ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
64
65 match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, 0, subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1 );
66 return occ;
67}
68
69template < class SymbolType >
71 if ( low >= high ) return;
72
73 int i = ( low + high ) / 2;
74
75 // index to the pattern
76 unsigned j = tree::exact::ForwardOccurrenceTest::occurrence ( subject, subjectSubtreeJumpTable, pattern, i );
77
78 // match was found
79 if ( j >= pattern.getContent ( ).size ( ) ) occ.insert ( i );
80
81 match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, low, i - bbcs[subject.getContent ( )[i]] + 1 );
82 match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, i + j - fba[j], high );
83}
84
85template < class SymbolType >
87 return match ( subject, tree::PrefixRankedPattern < SymbolType > ( pattern ) );
88}
89
90template < class SymbolType >
93 ext::map < common::ranked_symbol < SymbolType >, size_t > bbcs = tree::properties::ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern
95 ext::vector < int > subjectSubtreeJumpTable = tree::properties::SubtreeJumpTable::compute ( subject );
96
97 match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, 0, subject.getContent ( ).size ( ) - pattern.getContent ( ).size ( ) + 1 );
98 return occ;
99}
100
101template < class SymbolType >
103 if ( low >= high ) return;
104
105 int i = ( low + high ) / 2;
106
107 // index to the pattern
108 unsigned j = tree::exact::ForwardOccurrenceTest::occurrence ( subject, subjectSubtreeJumpTable, pattern, i );
109
110 // match was found
111 if ( j >= pattern.getContent ( ).size ( ) ) occ.insert ( i );
112
113 match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, low, i - bbcs[subject.getContent ( )[i]] + 1 );
114 match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, i + j - fba[j], high );
115}
116
117} /* namespace exact */
118
119} /* namespace arbology */
120
Definition: DeadZoneUsingBadCharacterShiftAndBorderArray.h:31
static void match_rec(ext::set< unsigned > &occ, const tree::PrefixRankedBarTree< SymbolType > &subject, const tree::PrefixRankedBarPattern< SymbolType > &pattern, ext::vector< size_t > &fba, ext::map< common::ranked_symbol< SymbolType >, size_t > &bbcs, ext::vector< int > &subjectSubtreeJumpTable, int low, int high)
Definition: DeadZoneUsingBadCharacterShiftAndBorderArray.h:70
static ext::set< unsigned > match(const tree::PrefixRankedBarTree< SymbolType > &subject, const tree::PrefixRankedBarTree< SymbolType > &pattern)
Definition: DeadZoneUsingBadCharacterShiftAndBorderArray.h:54
Definition: ranked_symbol.hpp:20
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
Tree pattern represented as linear sequece as result of preorder traversal with additional bar symbol...
Definition: PrefixRankedBarPattern.h:85
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarPattern.h:334
Tree structure represented as linear sequece as result of preorder traversal with additional bar symb...
Definition: PrefixRankedBarTree.h:78
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarTree.h:273
Tree pattern represented as linear sequece as result of preorder traversal. The representation is so ...
Definition: PrefixRankedPattern.h:77
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedPattern.h:262
Tree structure represented as linear sequece as result of preorder traversal. The representation is s...
Definition: PrefixRankedTree.h:71
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedTree.h:235
static size_t occurrence(const PrefixRankedBarTree< SymbolType > &subject, const ext::vector< int > &subjectSubtreeJumpTable, const PrefixRankedBarTree< SymbolType > &pattern, size_t subjectPosition, size_t patternStartIndex=0)
Definition: ForwardOccurrenceTest.h:42
static ext::vector< size_t > construct(const T &pattern)
Definition: BorderArrayNaive.h:59
static ext::map< common::ranked_symbol< SymbolType >, size_t > bcs(const tree::PrefixRankedBarPattern< SymbolType > &pattern)
Definition: ReversedBadCharacterShiftTable.h:44
static ext::vector< int > compute(const tree::PrefixRankedBarTree< SymbolType > &subject)
Definition: SubtreeJumpTable.h:49
Definition: BoyerMooreHorspool.h:22
int i
Definition: AllEpsilonClosure.h:118