-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayMap.h
91 lines (67 loc) · 1.58 KB
/
ArrayMap.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Created by Corey Caplan on 2/22/16.
//
#ifndef ARRAYMAP_ARRAYMAP_H
#define ARRAYMAP_ARRAYMAP_H
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Item {
int value;
string key;
};
class ArrayMap {
public:
/**
* Default constructor that initializes the ArrayMap to be of size one
*/
ArrayMap();
/**
* Puts the item into the map for the given key
*/
void put(string key, int item);
/**
* Gets the item for the given key
*/
int get(string key);
/**
* Removes the item for the given key and returns the value that was removed.
*/
int remove(string key);
void printContent();
~ArrayMap();
private:
/**
* Binary searches the #hashedValues array to find the index of where the hashedValue is entered.
*/
int binarySearchInsert(int hashedValue);
int linearSearchGet(int hashedValue);
int binarySearchGet(int hashedValue);
int spaceLeft;
int arraySize;
int *hashedValues;
Item **arrayMap;
/**
* @param index The location of the shift
*/
void shiftRemoval(int index);
/**
* @param index The location of the shift
*/
void shiftInsert(int index);
/**
* Hashes a string (key) to an integer value.
*/
int hash(string key);
/**
* Reallocates the array of hashes and items to a larger array.
*/
void reallocate();
/**
* Deallocates the array of hashes and items to a smaller array.
*/
void deallocate();
};
#endif //ARRAYMAP_ARRAYMAP_H