/////////////////////////////////////////////////////// // // hash.h // // 2/14/01 A suggested starting place for hash // table code for the word counting assignment. // /////////////////////////////////////////////////////// #ifndef HASH_H #define HASH_H // Set the mCounter field to 0 to indicate "empty slot of // hash table". struct WordCounter { string mWord; int mCounter; }; class HashTable { private: WordCounter *mWordArray; int mTableSize; int mNElements; // You might want a function like this for AddItem to call. Putting // the probing strategy in a separate function will make it easier // to test out separate probing strategies. int Probe( int currentIndex, int hashValue, const WordCounter& wc ); public: // The constructor should allocate enough memory for // the mWordArray to point to. The destructor should // get rid of the same. HashTable( int size ); ~HashTable(); // AddItem should either find an item with the given key // in the table and return a pointer to it, or add the // given item to the table and return a pointer to it. // // Returning a non-const pointer is dangerous, because you // don't want the caller to be able to mess with the structure of // the table itself. But for now, go ahead and use this // strategy if you wish. WordCounter *AddItem( const WordCounter& wc ); void Print(); }; int HashFunction( const string& s ); #endif