Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <array>
- #include <list>
- using namespace std;
- const int MAX = 100;
- //T must have a getKey() function
- template <class T>
- class HashTable
- {
- public:
- HashTable(void){
- size = 0;
- entries = 0;
- loadFactor = 0;
- };
- ~HashTable(void){
- delete[] la;
- };
- void add(T input){
- int loc = hashFunction((*input).getKey() ) ;
- la[loc].push_front(input);
- entries++;
- };
- void remove(T input){
- // list<T
- entries--;
- };
- T find(T input){
- int loc = hashfunction(input.getKey());
- list<T>::iterator iter = la[loc].begin();
- while(iter!= la[loc].end())
- {
- //if(iter)
- iter++;
- }
- };
- void setSize(int s){ size = s;};
- int getSize(){ return size;};
- void setTable(int s) { la = new list<T>[s]; };
- void printLF(){
- if(size>0 && entries >0)
- {
- loadFactor = entries / size;
- }
- else
- {
- loadFactor = 0;
- }
- cout << "Load Factor: " << loadFactor << endl << endl;
- };
- private:
- int size;
- int entries;
- float loadFactor;
- int hashFunction(string input){
- int x = 0;
- for(int i = 0; i < strlen(input.c_str()); i++)
- {
- x += (input.c_str())[i];
- }
- return h(x);
- };
- int h(int x){
- return (x % size);
- };
- int f(int i){};
- //needs to be an array of lists
- list<T>* la;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement