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

algo: covers: Extract common function isBorder

parent bad58dba
No related branches found
No related tags found
1 merge request!148Bp hruskaraj rebase
......@@ -159,6 +159,22 @@ protected:
return nextState;
}
 
/**
* Checks if a string represented by the state of the
* k-approximate deterministic suffix automaton is an exact border.
*
* @param state
* @param x the original string
* @param k maximum number of allowed errors
* @return true if state represents border, false otherwise
*/
template < class SymbolType >
static bool isBorder ( const State & state, const string::LinearString < SymbolType > & x, unsigned k ) {
Element lastElement = state.elements[state.elements.size ( ) - 1];
return ( state.elements[0].depth == state.depth && lastElement.depth == x.getContent ( ).size ( ) ) && ( lastElement.level == 0 ) && ( state.depth > k );
}
/**
* Makes actual set of (relaxed) approximate enhanced covers from the set of
* lfactors, so the set of pairs of end position of factor and length of
......
......@@ -19,19 +19,6 @@ public:
*/
template < class SymbolType >
static ext::set < string::LinearString < SymbolType > > compute ( const string::LinearString < SymbolType > & x, unsigned k );
private:
/**
* Checks if a string represented by the state of the backbone of
* k-approximate deterministic suffix automaton is a border.
*
* @param state
* @param x the original string
* @param k maximum number of allowed errors
* @return true if state represents border, false otherwise
*/
template < class SymbolType >
static bool isBorder ( const State & state, const string::LinearString < SymbolType > & x, unsigned k );
};
 
template < class SymbolType >
......@@ -70,12 +57,5 @@ ext::set < string::LinearString < SymbolType > > ApproximateEnhancedCoversComput
return getFactors ( x, result );
}
 
template < class SymbolType >
bool ApproximateEnhancedCoversComputation::isBorder ( const State & state, const string::LinearString < SymbolType > & x, unsigned k ) {
Element lastElement = state.elements[state.elements.size ( ) - 1];
return ( lastElement.depth == x.getContent ( ).size ( ) ) && ( lastElement.level == 0 ) && ( state.depth > k );
}
} /* namespace stringology::cover */
#endif /* APPROXIMATE_ENHANCED_COVERS_COMPUTATION_H */
......@@ -60,7 +60,7 @@ ext::set < string::LinearString < SymbolType > > RelaxedApproximateEnhancedCover
State firstState = constrFirstState ( x, k, symbol );
 
// check if the first character is a border (makes sense only for k = 0)
if ( ( firstState.elements[0].depth == 1 ) && ( firstState.elements[firstState.elements.size ( ) - 1].depth == x.getContent ( ).size ( ) ) && ( k == 0 ) )
if ( isBorder ( firstState, x, k ) )
updateEnhCov ( firstState, result, h );
 
processState ( x, k, firstState, result, h );
......
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