-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.cpp
50 lines (42 loc) · 1.1 KB
/
hash.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
#include "hash.h"
/*
template <class valueType> hashTable<valueType>::hashTable()
{
amount = 0;
}
template <class valueType>hashTable<valueType>::hashTable(unsigned int n){
amount = n;
for (unsigned i = 0; i < n; ++i){
value.push_back(NULL);
}
}
template <class valueType> bool hashTable<valueType>::add(valueType *element, unsigned (*hash_function)(valueType)){
unsigned index = hash_function(&element);
index %= amount;
unsigned count = 0;
while (value[index]!=NULL){
++count;
if (count > amount){
return false;
}
++index;
index %= amount;
}
value[index] = element;
return true;
}
template <class valueType> valueType* hashTable<valueType>::find(valueType *X, unsigned (*hash_function)(valueType), bool (*comp)(valueType, valueType)){
unsigned index = hash_function(&X);
index %= amount;
unsigned count = 0;
while (!comp(value[index], X)){
++count;
if (count > amount){
return NULL;
}
++index;
index %= amount;
}
return value[index];
}
*/