diff --git a/lab2/dictionary.cc b/lab2/dictionary.cc index 6747a69..51d5ba7 100644 --- a/lab2/dictionary.cc +++ b/lab2/dictionary.cc @@ -1,7 +1,6 @@ #include "dictionary.h" #include "word.h" #include -#include #include #include #include @@ -13,7 +12,7 @@ using std::vector; Dictionary::Dictionary() {} bool Dictionary::contains(const string &word) const { - int l = word.length(); + auto l = word.length(); Word w = Word(word); if (std::find(this->words[l].begin(), this->words[l].end(), w) != std::end(this->words[l])) { @@ -60,9 +59,9 @@ int Dictionary::slurp(path p) { std::string line; while (std::getline(file, line)) { - if (line.size() > MAXLEN) - continue; - words[line.size()].push_back(Word(line)); + // Words larger than max gets placed in the topmost bucket + words[std::min(line.size(), static_cast(MAXLEN) - 1)].push_back( + Word(line)); } file.close();