project4 soln

project4 soln - / Dictionary.cpp #define...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#define _HAS_ITERATOR_DEBUGGING 0 #define _SECURE_SCL 0 #include "Dictionary.h" #include <string> #include <vector> #include <cctype> #include <algorithm> using namespace std; // This class does the real work of the implementation. const size_t NBUCKETS = 49999; class DictionaryImpl { public: DictionaryImpl() {} ~DictionaryImpl() {} void insert(string word); void lookup(string letters, void callback(const string&)) const; private: struct HashEntry { string key; vector<string> words; : key(k) { words.push_back(w); } }; vector<HashEntry> m_bucket[NBUCKETS]; static size_t hash(const string& s); static void removeNonLetters(string& s); }; void DictionaryImpl::insert(string word) { removeNonLetters(word); if ( ! word.empty()) { string key(word); sort(key.begin(), key.end()); vector<HashEntry>& b = m_bucket[hash(key)]; for (size_t k = 0; k < b.size(); k++) { if (b[k].key == key) { b[k].words.push_back(word); return; } } b.push_back(HashEntry(key, word));
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

project4 soln - / Dictionary.cpp #define...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online