/****************************************************************** * Memorial University of Newfoundland * Engineering 4892 Data Structures * * $RCSfile: assign6.h,v $ $Revision: 1.1 $ * $Date: 2001-07-22 16:57:52-02:30 $ * $State: Exp $ * * Include file for Assignment 6. * ******************************************************************/ /****************************************************************** * REVISION HISTORY * * $Log: assign6.h,v $ * Revision 1.1 2001-07-22 16:57:52-02:30 dpeters * Initial revision * * ******************************************************************/ #ifndef ASSIGN6_DEF #define ASSIGN6_DEF #include template class HashTable { public: enum Status { Ok, NoSuchElement, DuplicateElement }; HashTable() { err = Ok; } // Post: Empty table constructed ~HashTable() { } // Post: Table destroyed Status insert(const Record& r); // Post: Result = Ok <-> r is insterted into the table /\ // Result = DuplicateElement <-> r already existed in the table Status remove(const Record& r); // Post: Result = Ok <-> (the element, d, in the table // such that hash(r) == hash(d) /\ d == r is // removed) /\ // Result = NoSuchElement <-> No such element exists. Status retrieve(Record& r) const; // Post: Result = Ok <-> (r is assigned the value stored in the table // such that hash(r) == hash(r') /\ r' == r) /\ // Result = NoSuchElement <-> No such element exists. Status getStatus() const { return err; } // Inserted by Daniel Mastropietro // July 30 2001 void resetErr () { err = Ok; } int getSize (const Record& r) { return table[hash(r)].size(); } bool isEmpty (const Record& r) { return table[hash(r)].empty(); } // End Insert private: list table[Size]; mutable Status err; int hash(const Record& key) const; // Pre: Record::operator % (int r) is defined and returns a value in the // range 0 <= Result < r // Post: 0 <= Result < Size }; template int HashTable::hash(const Record& key) const { return key % Size; // Note: STL defines a collection of template functions hash on many // standard types. In practical programming you sould simply use them and // define your own for new types. For this assignment however, I've defined // it slightly differently. } #endif