-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderedMap.h
35 lines (33 loc) · 910 Bytes
/
OrderedMap.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
#ifndef _ORDEREDMAP_H_
#define _ORDEREDMAP_H_
template <class KEY, class TYPE>
class OrderedMap{
public:
bool find(const KEY& key) {
if (this->keyTypeMap.find(key) == this->keyTypeMap.end()){
return false;
}
return true;
}
TYPE& operator[] (const KEY& key) {
if (!this->find(key)){
this->keyVec.push_back(key);
}
return this->keyTypeMap[key];
}
void front(KEY* k, TYPE* v) {
*k = this->keyVec.front();
*v = this->keyTypeMap[(*k)];
}
bool at(unsigned int idx, KEY* k, TYPE* v) {
if (idx >= this->size()) false;
*k = this->keyVec[idx];
*v = this->keyTypeMap[(*k)];
return true;
}
unsigned int size() const { return this->keyVec.size();} ;
private:
std::vector < KEY > keyVec;
std::map < KEY, TYPE > keyTypeMap;
};
#endif /* _ORDEREDMAP_H_ */