Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
SuffixArrayFactors.h
Go to the documentation of this file.
1
6#pragma once
7
9#include <string/LinearString.h>
10#include <ext/algorithm>
11
12namespace stringology {
13
14namespace query {
15
23public:
30 template < class SymbolType >
32
33};
34
35template < class SymbolType >
37
38 auto comparator = [ & ] ( const ext::vector < SymbolType > & first, unsigned firstIndex, const ext::vector < SymbolType > & second, unsigned secondIndex, unsigned limit ) {
39 for ( ; firstIndex < first.size ( ) && secondIndex < second.size ( ) && limit > 0; ++ firstIndex, ++ secondIndex, --limit ) {
40 auto res = first [ firstIndex ] <=> second [ secondIndex ];
41
42 if ( res != 0 )
43 return res;
44 }
45
46 if ( limit == 0 )
47 return std::strong_ordering::equal;
48
49 return ( first.size ( ) - firstIndex ) <=> ( second.size ( ) - secondIndex );
50 };
51
52 // The value returned by comparator indicates whether the first argument is considered to go before the second.
53 ext::vector < unsigned >::const_iterator low = std::lower_bound ( suffixArray.getData ( ).begin ( ), suffixArray.getData ( ).end ( ), string, [ & ] ( unsigned first, const string::LinearString < SymbolType > & str ) {
54 return comparator ( suffixArray.getString ( ).getContent ( ), first, str.getContent ( ), 0, str.getContent ( ).size ( ) ) < 0;
55 } );
56
57 // The value returned by comparator indicates whether the first argument is considered to go before the second.
58 ext::vector < unsigned >::const_iterator high = std::upper_bound ( suffixArray.getData ( ).begin ( ), suffixArray.getData ( ).end ( ), string, [ & ] ( const string::LinearString < SymbolType > & str, unsigned second ) {
59 return comparator ( str.getContent ( ), 0, suffixArray.getString ( ).getContent ( ), second, str.getContent ( ).size ( ) ) < 0;
60 } );
61
62 return ext::set < unsigned > ( low, high );
63}
64
65} /* namespace query */
66
67} /* namespace stringology */
68
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
typename std::vector< T, Alloc >::const_iterator const_iterator
The type of constant values iterator.
Definition: vector.hpp:67
Suffix array string index. Linear representation of all suffixes ordered lexicographically....
Definition: SuffixArray.h:51
const ext::vector< unsigned > & getData() const &
Definition: SuffixArray.h:181
Linear string.
Definition: LinearString.h:57
Definition: SuffixArrayFactors.h:22
static ext::set< unsigned > query(const indexes::stringology::SuffixArray< SymbolType > &suffixArray, const string::LinearString< SymbolType > &string)
Definition: SuffixArrayFactors.h:36
p second
Definition: ToRegExpAlgebraic.h:126
return res
Definition: MinimizeByPartitioning.h:145
Definition: ArithmeticCompression.h:18