Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #pragma once
  2. #include <array>
  3. #include <list>
  4. using namespace std;
  5.  
  6. const int MAX = 100;
  7.  
  8. //T must have a getKey() function
  9. template <class T>
  10. class HashTable
  11. {
  12. public:
  13. HashTable(void){
  14. size = 0;
  15. entries = 0;
  16. loadFactor = 0;
  17.  
  18. };
  19.  
  20. ~HashTable(void){
  21. delete[] la;
  22. };
  23.  
  24.  
  25. void add(T input){
  26. int loc = hashFunction((*input).getKey() ) ;
  27. la[loc].push_front(input);
  28. entries++;
  29. };
  30.  
  31.  
  32. void remove(T input){
  33. // list<T
  34. entries--;
  35. };
  36.  
  37.  
  38. T find(T input){
  39. int loc = hashfunction(input.getKey());
  40. list<T>::iterator iter = la[loc].begin();
  41.  
  42. while(iter!= la[loc].end())
  43. {
  44. //if(iter)
  45. iter++;
  46. }
  47.  
  48. };
  49.  
  50. void setSize(int s){ size = s;};
  51. int getSize(){ return size;};
  52.  
  53. void setTable(int s) { la = new list<T>[s]; };
  54.  
  55. void printLF(){
  56. if(size>0 && entries >0)
  57. {
  58. loadFactor = entries / size;
  59. }
  60. else
  61. {
  62. loadFactor = 0;
  63. }
  64. cout << "Load Factor: " << loadFactor << endl << endl;
  65. };
  66.  
  67. private:
  68. int size;
  69. int entries;
  70. float loadFactor;
  71. int hashFunction(string input){
  72. int x = 0;
  73. for(int i = 0; i < strlen(input.c_str()); i++)
  74. {
  75. x += (input.c_str())[i];
  76. }
  77.  
  78. return h(x);
  79. };
  80.  
  81.  
  82. int h(int x){
  83. return (x % size);
  84. };
  85.  
  86. int f(int i){};
  87.  
  88. //needs to be an array of lists
  89.  
  90. list<T>* la;
  91.  
  92. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement