-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashmap.h
46 lines (38 loc) · 1.28 KB
/
hashmap.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
#pragma once
#include <vector>
#include <ostream>
#include <istream>
using namespace std;
class hashmap
{
public:
hashmap(); // constructor
~hashmap(); // destructor
// void build_Queue(priority_queue<HuffmanNode*, vector<HuffmanNode*>, prioritize> pq);
int get(int key) const;
void put(int key, int value);
bool containsKey(int key);
vector<int> keys() const;
int size();
void sanityCheck();
hashmap(const hashmap &myMap); // copy constructor
hashmap& operator= (const hashmap &myMap); // equals operator
// overloads the << operator, which is VERY useful printing the hashmap
// or writing it to a stream/file.
friend ostream &operator<<(ostream &out, hashmap &myMap);
// overloads the >> operator, which is VERY useful for extracting it from
// streams/files.
friend istream &operator>>(istream &in, hashmap &myMap);
private:
struct key_val_pair {
int key;
int value;
key_val_pair* next;
};
typedef key_val_pair** bucketArray; // pointer to a list of keyvalpairs
bucketArray createBucketArray(int nBuckets); // declare function
int hashFunction(int input) const; // declare function
bucketArray buckets; // actual list of buckets declaration
int nBuckets;
int nElems;
};