Skip to content
Snippets Groups Projects
Commit bad58dba authored by Rajmund Hruška's avatar Rajmund Hruška Committed by Tomáš Pecka
Browse files

algo: covers: Update documentation, use emplace_back instead of push_back

parent a7f4dab1
No related branches found
No related tags found
1 merge request!148Bp hruskaraj rebase
......@@ -13,14 +13,22 @@
 
namespace stringology::cover {
 
/**
* Auxiliary abstract class used to extract common functions used by both
* ApproximateEnhancedCoversComputation and
* RelaxedApproximateEnhancedCoversComputation.
*/
class ApproximateEnhancedCoversCommon {
public:
/**
* The purpose of this virtual destructor is to make the whole class abstract.
*/
virtual ~ApproximateEnhancedCoversCommon ( ) = 0;
 
protected:
/**
* A simple structure used to represent the element of d-subset corresponding
* to a state q of a nondeterministic finite automaton.
* to a state q of a nondeterministic approximate suffix automaton.
*/
struct Element {
unsigned depth, level;
......@@ -32,12 +40,16 @@ protected:
* State of the deterministic trie-like k-approximate suffix automaton.
*/
struct State {
// depth is equal to the number of transitions from the starting state to
// this state
unsigned depth = 0;
 
// Pair of two integers - depth of the element with level 0 and length of
// corresponding factor
ext::pair < unsigned, unsigned > lfactor;
ext::vector < Element > elements;
// d-subset of this state
ext::vector < Element > elements;
 
State ( ) = default;
~State ( ) = default;
......@@ -81,6 +93,7 @@ protected:
static void updateEnhCov ( const State & state, ext::set < ext::pair < unsigned, unsigned > > & enhCovers, unsigned & h ) {
unsigned hNext = distEnhCov ( state );
 
// update the current set if this state covers more positions
if ( hNext > h ) {
h = hNext;
enhCovers.clear ( );
......@@ -108,9 +121,9 @@ protected:
 
for ( size_t i = 0; i < x.getContent ( ).size ( ); ++i ) {
if ( symbol == x.getContent ( )[i] )
firstState.elements.push_back ( Element ( i + 1, 0 ) );
firstState.elements.emplace_back ( i + 1, 0 );
else if ( k > 0 )
firstState.elements.push_back ( Element ( i + 1, 1 ) );
firstState.elements.emplace_back ( i + 1, 1 );
}
 
return firstState;
......@@ -136,10 +149,10 @@ protected:
for ( const auto & element : previousState.elements )
if ( element.depth < x.getContent ( ).size ( ) ) {
if ( symbol == x.getContent ( )[element.depth] ) {
nextState.elements.push_back ( Element ( element.depth + 1, element.level ) );
nextState.elements.emplace_back ( element.depth + 1, element.level );
nextState.lfactor = ext::pair < unsigned, unsigned > ( element.depth + 1, nextState.depth );
} else if ( element.level < k ) {
nextState.elements.push_back ( Element ( element.depth + 1, element.level + 1 ) );
nextState.elements.emplace_back ( element.depth + 1, element.level + 1 );
}
}
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment