39 template<
typename KeyType,
typename ValueType>
42 vector<pair<KeyType, ValueType> *> _data;
43 map<KeyType, unsigned> _index;
56 size_t size()
const {
return _data.size(); };
60 void insert(
const KeyType& key,
const ValueType& v);
62 void erase(
const KeyType& key);
64 int find(
const KeyType& key)
const;
70 const ValueType& operator[](
unsigned int indx)
const;
72 ValueType& operator[](
unsigned int indx);
74 const ValueType& operator[](
const KeyType& key)
const;
76 ValueType& operator[](
const KeyType& key);
81 template<
typename KeyType,
typename ValueType>
87 template<
typename KeyType,
typename ValueType>
92 _data.reserve(m._data.size());
93 for (
typename vector<pair<KeyType, ValueType> *>::const_iterator it = m._data.begin();
94 it != m._data.end(); it++) {
95 _data.push_back(
new pair<KeyType, ValueType>(*it));
99 template<
typename KeyType,
typename ValueType>
105 template<
typename KeyType,
typename ValueType>
108 for (
typename vector<pair<KeyType, ValueType> *>::iterator it = _data.begin();
109 it != _data.end(); it++) {
117 template<
typename KeyType,
typename ValueType>
120 typename map<KeyType, unsigned>::iterator it = _index.find(key);
121 if (it != _index.end()) {
122 _data[it->second]->second = v;
124 _index.insert(it, make_pair(key, (
unsigned)_data.size()));
125 _data.push_back(
new pair<KeyType, ValueType>(key, v));
129 template<
typename KeyType,
typename ValueType>
132 typename map<KeyType, unsigned>::iterator it = _index.find(key);
133 DRWN_ASSERT(it != _index.end());
136 delete _data[it->second];
137 for (
unsigned i = it->second + 1; i < _data.size(); i++) {
138 _data[i - 1] = _data[i];
143 for (
typename map<KeyType, unsigned>::iterator jt = _index.begin();
144 jt != _index.end(); jt++) {
145 if (jt->second > it->second)
151 template<
typename KeyType,
typename ValueType>
154 typename map<KeyType, unsigned>::const_iterator it = _index.find(key);
155 if (it == _index.end()) {
158 return (
int)it->second;
162 template<
typename KeyType,
typename ValueType>
167 _data.reserve(m._data.size());
168 for (
typename vector<pair<KeyType, ValueType> *>::const_iterator it = m._data.begin();
169 it != m._data.end(); it++) {
170 _data.push_back(
new pair<KeyType, ValueType>(*it));
178 template<
typename KeyType,
typename ValueType>
181 return _data[indx]->second;
184 template<
typename KeyType,
typename ValueType>
187 return _data[indx]->second;
190 template<
typename KeyType,
typename ValueType>
193 typename map<KeyType, unsigned>::const_iterator it = _index.find(key);
194 return _data[it->second]->second;
197 template<
typename KeyType,
typename ValueType>
200 typename map<KeyType, unsigned>::iterator it = _index.find(key);
201 if (it == _index.end()) {
202 _index.insert(it, make_pair(key, (
unsigned)_data.size()));
203 _data.push_back(
new pair<KeyType, ValueType>(key, ValueType(0)));
204 return _data.back()->second;
207 return _data[it->second]->second;
void clear()
clear all entries from the map
Definition: drwnOrderedMap.h:106
size_t size() const
returns the number of entries in the map
Definition: drwnOrderedMap.h:56
~drwnOrderedMap()
destructor
Definition: drwnOrderedMap.h:100
void erase(const KeyType &key)
remove the entry in the map corresponding to key key
Definition: drwnOrderedMap.h:130
drwnOrderedMap()
default constructor
Definition: drwnOrderedMap.h:82
drwnOrderedMap< KeyType, ValueType > & operator=(const drwnOrderedMap< KeyType, ValueType > &m)
assignment operator
Definition: drwnOrderedMap.h:163
void insert(const KeyType &key, const ValueType &v)
Inserts value v into the map at the end position with key key. If the key already exists then the val...
Definition: drwnOrderedMap.h:118
int find(const KeyType &key) const
find the index of an entry in the map (-1 if the key does not exist)
Definition: drwnOrderedMap.h:152
Provides a datastructure for that can be indexed by a KeyType (usually a string) or unsigned integer...
Definition: drwnOrderedMap.h:40
const ValueType & operator[](unsigned int indx) const
index the indx-th entry in the map
Definition: drwnOrderedMap.h:179