// SuffixList03.cpp // tom bailey 9 mar 06 // Define the SuffixList methods. // tom bailey 17 mar 06 // Sort the suffixes, thus a true suffix list. // tom bailey 20 mar 06 // SuffixList includes an empty substring. // Find longest internal match. #include "SuffixList03.h" using std::string; using std::ostream; #include using std::sort; using std::pair; using std::make_pair; SuffixList::SuffixList( const string & str ) { StrCIt it = str.begin(); StrCIt itEnd = str.end(); theList.push_back( StringSegment( it, itEnd ) ); while( it != itEnd ) { ++it; theList.push_back( StringSegment( it, itEnd ) ); } sort( theList.begin(), theList.end() ); } pair SuffixList::longestMatch() const { size_t bestMatch = 0; size_t matchAt = 0; for( size_t i=1; i bestMatch ) { bestMatch = thisMatch; matchAt = i; } } if( matchAt == 0 ) { return make_pair( theList.at(0), theList.at(0) ); } else { return make_pair( theList.at(matchAt-1), theList.at(matchAt) ); } } void SuffixList::write( ostream & outfile, size_t limit, string term ) const { for( size_t i=0; i