-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTable.hpp
More file actions
47 lines (36 loc) · 1.39 KB
/
Copy pathHashTable.hpp
File metadata and controls
47 lines (36 loc) · 1.39 KB
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
// HashTable.hpp
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#include <string>
// separate chaining hash table.
// used for deleted elements of BloomFilter.
class HashTable {
public:
// q := the size of the HashTable, a prime number.
HashTable(int q);
// calculates the hash of an element.
// hash function used: x mod size of HashTable.
// used by the insert() function.
int hash(std::string element) const;
// insert a string into the hash table.
void insert(std::string element);
// resizes the table to about double the size (whenever load factor >= 0.7).
void resizeTable();
// delete an element from the hash table.
void remove(std::string element);
// returns 1 if the element is in the hash table.
// returns 0 otherwise.
bool find(std::string element) const;
// testing purposes (to test insert without using find())
int getNumEntries() const { return numEntries; }
private:
// linked list implementation for separate hashing.
struct Node {
std::string element;
Node* next;
};
int size; // size of HashTable, a prime number.
int numEntries; // for testing purposes, and for calculating the load factor.
Node** hashTable; // a separate chaining hash table.
};
#endif // HASH_TABLE_H