-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashTable.h
58 lines (50 loc) · 1.22 KB
/
hashTable.h
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
#ifndef HASHTABLE_H
#define HASHTABLE_H
#include <string>
#include <vector>
#include <list>
/*
*Need this format for Robin Hood Hashing. PSL is used to determine the hashed
* object's place in the table.
*Using the following guide: https://programming.guide/robin-hood-hashing.html
*/
template <typename T>
struct hashedObj{
std::string key;
T val;
int PSL;
};
template <typename T>
class HashTable{
private:
std::vector<int> primesList;
std::vector<hashedObj<T>> table;
std::vector<int>::iterator currSizeIter;
int numElems = 0;
/*Hashing methods*/
unsigned int keygen(std::string p);
int rehash();
int hashHelper(std::string key, T value);
public:
/*Table info*/
const int MAX_TABLE_SIZE = 1000000;
const float HASH_LOAD_FACTOR = .75;
/*Error catching*/
const int ERR_ITEM_NOT_FOUND = -3;
const int ERR_MAX_TABLE_LOAD = -2;
const int ERR_TABLE_MAX_SIZE = -1;
const int SUCCESS_HASH = 0;
/*Table creation*/
HashTable();
HashTable(size_t length);
int hash(std::string key, T value);
/*Getters*/
int getNumElems();
int length();
/*User functions*/
void printAll();
void printRange(int i, int j);
int find(std::string key, T value);
int erase(std::string key, T value);
};
#endif