-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhashtable.cpp
109 lines (88 loc) · 2.16 KB
/
hashtable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <cstdlib>
#include <iostream>
#include "hashtable.h"
#include "hashFunction.h"
#include "euclideanNode.h"
using namespace std;
template <class T>
HashTable<T>::HashTable(int NBuckets, HashFunction<T>* hashMethod)
{
if(NBuckets <= 0) return;
nBuckets = NBuckets;
totalSize = 0;
buckets = new List<T> *[nBuckets]; //kataskeuazoume ena pinaka apo listes
for(int i = 0; i < nBuckets; i++)
{
buckets[i] = new List<T>();
}
gFunction = hashMethod; //orizoume thn hash function
}
template <class T>
HashTable<T>::~HashTable()
{
for(int i = 0; i < nBuckets; i++)
{
delete buckets[i];
}
delete []buckets;
}
template <class T>
unsigned int HashTable<T>::hashFunction(T key) //epistrefei thn timh ths hash function
{
return gFunction->HashFunctionHash(key);
}
template <class T>
int HashTable<T>::get_TotalSize()
{
return totalSize;
}
template <class T>
int HashTable<T>::get_nBuckets()
{
return nBuckets;
}
template <class T>
HashFunction<T>* HashTable<T>::getHashFunction()
{
return gFunction;
}
template <class T>
Node<T>* HashTable<T>::get_bucket(T key) //epistregei thn lista pou antistixei se auto to bucket
{
return buckets[hashFunction(key)]->get_begin();
}
template <class T>
List<T>* HashTable<T>::get_bucketList(T key)
{
return buckets[hashFunction(key)];
}
template <class T>
void HashTable<T>::insertNode(T data)
{
totalSize++;
buckets[hashFunction(data)]->insertEnd(data); //vazei to stoixeio sthn thesi pou leei to hashfunction
}
template <class T>
bool HashTable<T>::checkEmpty() //elenxei an einai keno to hashtable
{
for(int i=0;i< nBuckets;i++)
{
if(buckets[i]->checkEmpty())
{
return true;
}
}
return false;
}
template <class T>
void HashTable<T>::printSizeOfBuckets() //emfanizei to megethos tou kathe bucket
{
for(int i =0; i < nBuckets; i++)
{
cout<<i<<" "<<buckets[i]->getSize()<<endl;
}
}
template class HashTable<ClusterNode<Vector*>*>;
template class HashTable<ClusterNode<Hamming*>*>;
template class HashTable<ClusterNode<EuclideanNode*>*>;
template class HashTable<ClusterNode<MatrixPoint*>*>;