-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hash.cpp
44 lines (41 loc) · 1.07 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
// Name: Kathan Sanghavi
// ID: 201901053
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include "structs.h"
using namespace std;
template<typename T> // made using template so it can be used for different node structures.
class Hash
{
private:
int size;
LinkList<T> *table;
public:
Hash(int s)
{
size = s;
table = new LinkList<T>[s];
}
int hashFunction(long int x)
{
return x%size;
}
void hashInsert(T *n)
{
table[hashFunction(n->ID)].linkInsert(n);
}
char* hashDelete(long int ID1) // delete by ID and return the name. Name can be further used if needed.
{
char* name = table[hashFunction(ID1)].linkDelete(ID1);
return name;
}
T* hashSearch(long int ID1)
{
T* node = table[hashFunction(ID1)].linkSearch(ID1);
return node;
}
};