/* table.h */ struct node { node * next; char * tempHashTable[1010]; }; /*Table ADT*/ class table { public: table(); ~table(); int adtHashFunction(const int hashsize, char * cpKey); //ADT hash function int adtChain(const int hashsize, char * cpKey); //ADT collision resolution function int adtRemove(const int hashsize, char * cpKey); //ADT removal int adtRetrieve(const int hashsize, char * cpKey, char * returnedList); //ADT retrieve (but NOT display) private: int adtHashPosition; //Position to add in the hash table node * head; node * current; }; /* table.cpp */ #include #include using namespace std; #include "table.h" #include "clientProgram.h" table::table() { } table::~table() { } int table::adtHashFunction(const int hashsize, char * cpKey) { table t; adtHashPosition = 0; int len = strlen(cpKey)+1; char cpKeyArray[len]; char adtHashTable[hashsize][len]; for(int i= 0; i < hashsize; i++) { *adtHashTable[i] = '\0'; } for(int i = 0; i < strlen(cpKey); i++) { //add each letter of the clients key for the hash position adtHashPosition = adtHashPosition + cpKey[i]; } //mod hash position by 1009 to get a constrained number adtHashPosition = adtHashPosition % hashsize; if(adtHashTable[adtHashPosition][0] == '\0') { cout << adtHashTable[adtHashPosition] << endl; //cout << adtHashPosition << endl; strcpy(adtHashTable[adtHashPosition],cpKey); cout << adtHashTable[adtHashPosition] << endl; } else { //LINKED LIST STUFF HERE! cout << adtHashTable[adtHashPosition-1] << endl; cout << adtHashPosition << endl; cout << "ERRRRROOOOOORRRRR! STUFFS HUR!" << endl; } return 1; } int table::adtChain(const int hashsize, char * cpKey) { /* node * temp = adtHashTable[adtHashPosition]; adtHashTable[adtHashPosition] = new node; strcpy(adtHashTable[adtHashPosition], cpKey); adtHashTable[adtHashPosition]->next = temp; */ return 1; } int table::adtRemove(const int hashsize, char * cpKey) { } int table::adtRetrieve(const int hashsize, char * cpKey, char * returnedList) { for(int i = 0; i < strlen(cpKey); i++) { adtHashPosition = adtHashPosition + cpKey[i]; } adtHashPosition = adtHashPosition % 1009; /* if(adtHashTable[adtHashPosition]) return 1; else return 0; */ }