diff --git a/alib2algo/src/stringology/transform/BeginToEndIndex.cpp b/alib2algo/src/stringology/transform/BeginToEndIndex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..15a199ebcb97cf4f0b3f201bd9ca1d652a369325 --- /dev/null +++ b/alib2algo/src/stringology/transform/BeginToEndIndex.cpp @@ -0,0 +1,20 @@ +/* + * BeginToEndIndex.cpp + * + * Created on: 5. 11. 2014 + * Author: Jan Travnicek + */ + +#include "BeginToEndIndex.h" +#include <registration/AlgoRegistration.hpp> + +namespace { + +auto BeginToEndIndexLinearString = registration::AbstractRegister < stringology::transform::BeginToEndIndex, ext::set < unsigned >, const string::LinearString < > &, const ext::set < unsigned > & > ( stringology::transform::BeginToEndIndex::transform, "pattern", "indexes" ).setDocumentation ( +"Transforms a set of occurrences represented by end indexes to set of occurrences representing by start indexes.\n\ +\n\ +@param pattern the pattern that was being searched for\n\ +@param indexes the original occurrences\n\ +@return the set of transformed occurences" ); + +} /* namespace */ diff --git a/alib2algo/src/stringology/transform/BeginToEndIndex.h b/alib2algo/src/stringology/transform/BeginToEndIndex.h new file mode 100644 index 0000000000000000000000000000000000000000..b064e46ddc230803a89bd14a0126e25f2668615b --- /dev/null +++ b/alib2algo/src/stringology/transform/BeginToEndIndex.h @@ -0,0 +1,50 @@ +/* + * BeginToEndIndex.h + * + * Created on: 5. 11. 2014 + * Author: Jan Travnicek + */ + +#ifndef _STRINGOLOGY_BEGIN_TO_END_INDEX_H_ +#define _STRINGOLOGY_BEGIN_TO_END_INDEX_H_ + +#include <alib/set> + +#include <string/LinearString.h> + +namespace stringology { + +namespace transform { + +/** + */ +class BeginToEndIndex { +public: + /** + * Transforms a set of occurrences represented by end indexes to set of occurrences representing by start indexes. + * + * \tparam SymbolType the type of symbols in the string + * + * \param pattern the pattern that was being searched for + * \param indexes the original occurrences + * \return the set of transformed occurences + */ + template < class SymbolType > + static ext::set < unsigned > transform ( const string::LinearString < SymbolType > & pattern, const ext::set < unsigned > & indexes ); +}; + +template < class SymbolType > +ext::set < unsigned > BeginToEndIndex::transform ( const string::LinearString < SymbolType > & pattern, const ext::set < unsigned > & indexes ) { + ext::set < unsigned > res; + + for ( unsigned index : indexes ) + res.insert ( index - pattern.getContent ( ).size ( ) ); + + return res; +} + +} /* namespace transform */ + +} /* namespace stringology */ + +#endif /* _STRINGOLOGY_BEGIN_TO_END_INDEX_H_ */