-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMap.cpp
More file actions
47 lines (38 loc) · 740 Bytes
/
Map.cpp
File metadata and controls
47 lines (38 loc) · 740 Bytes
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
#include "Map.h"
int Map::hash(string key)
{
int sum = 0;
for(int i=0;i < (int)key.length();i++)
sum+=key[i];
return sum;
}
Map::Map()
{
for(int i=0;i<999999;i++)
{
array.push_back(new vector< pair<string,int>* >);
}
}
void Map::put(string key, int value)
{
vector< pair<string, int>* > * v = array[hash(key)];
v->push_back(new pair<string, int>(key, value));
}
int Map::get(string key)
{
vector< pair<string, int>* > * v = array[hash(key)];
for(int i=0; i< (int)v->size(); i++)
{
pair<string, int>* current_pair = (*v)[i];
if(current_pair->first == key)
return current_pair->second;
}
return -1;
}
bool Map::exists(string key)
{
return false;
}
void Map::remove(string key)
{
}