-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.cpp
More file actions
40 lines (33 loc) · 779 Bytes
/
Dictionary.cpp
File metadata and controls
40 lines (33 loc) · 779 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
#include "Dictionary.h"
#include <utility>
String& Dictionary::operator[](String key){
for(int i = 0; i < pairs.size(); i++){
if (pairs[i].first == key){
return pairs[i].second;
}
}
pairs.push_back(StringPair(key,"dummy"));
return pairAt(size()-1).second;
}
String Dictionary::toString(){
String res = "dict<";
for(int i = 0; i < pairs.size(); i++){
res += pairs[i].first + ": " + pairs[i].second;
if (i != pairs.size()-1){
res += ", ";
}
}
res += ">";
return res;
}
StringPair& Dictionary::pairAt(const int i){
if (i < size()){
return pairs[i];
}
}
void Dictionary::append(Dictionary dict){
pairs.insert(pairs.end(), dict.pairs.begin(), dict.pairs.end());
}
int Dictionary::size(){
return pairs.size();
}