| 39 | }; |
| 40 | |
| 41 | vector<string> Dictionary::getDescendants( const string &word ) const |
| 42 | { |
| 43 | vector<string> result; |
| 44 | set<char> foundLetters; |
| 45 | |
| 46 | // we want to figure out what letters follow 'word' |
| 47 | // so for "victor" we want 'i' (victories), 's' (victors), 'y' (victory) |
| 48 | pair<vector<string>::const_iterator, vector<string>::const_iterator> range; |
| 49 | range = std::equal_range( mWords.begin(), mWords.end(), word, CompareStringPrefix( word.size() ) ); |
| 50 | |
| 51 | // iterate all the words in our range, and add their last letter to our set of 'foundLetters' |
| 52 | for( vector<string>::const_iterator wordIt = range.first; wordIt != range.second; ++wordIt ) { |
| 53 | if( wordIt->size() > word.size() ) |
| 54 | foundLetters.insert( (*wordIt)[word.size()] ); |
| 55 | } |
| 56 | |
| 57 | // now iterate all the foundLetters; each result word will be 'word' + foundLetter |
| 58 | // ex: victor + i (victories) |
| 59 | for( set<char>::const_iterator letIt = foundLetters.begin(); letIt != foundLetters.end(); ++letIt ) |
| 60 | result.push_back( word + *letIt ); |
| 61 | |
| 62 | return result; |
| 63 | } |
| 64 | |
| 65 | bool Dictionary::isCompleteWord( const std::string &word ) const |
| 66 | { |
no test coverage detected