From bad58dba2d4835b7c3d9f058ca6f037baeb950e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rajmund=20Hru=C5=A1ka?= <rajmund.hruska@gmail.com> Date: Sat, 30 May 2020 23:45:27 +0200 Subject: [PATCH] algo: covers: Update documentation, use emplace_back instead of push_back --- .../cover/ApproximateEnhancedCoversCommon.h | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/alib2algo/src/stringology/cover/ApproximateEnhancedCoversCommon.h b/alib2algo/src/stringology/cover/ApproximateEnhancedCoversCommon.h index 5775ceccef..bd995be355 100644 --- a/alib2algo/src/stringology/cover/ApproximateEnhancedCoversCommon.h +++ b/alib2algo/src/stringology/cover/ApproximateEnhancedCoversCommon.h @@ -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 ); } } -- GitLab