10 #ifndef SMALLMAP_TYPE_HPP
11 #define SMALLMAP_TYPE_HPP
25 template <
typename T,
typename U>
26 struct SmallMap : std::vector<std::pair<T, U> > {
27 typedef std::pair<T, U> Pair;
28 typedef Pair *iterator;
29 typedef const Pair *const_iterator;
41 inline typename std::vector<Pair>::const_iterator
Find(
const T &key)
const
43 typename std::vector<Pair>::const_iterator it;
44 for (it = std::vector<Pair>::begin(); it != std::vector<Pair>::end(); it++) {
45 if (key == it->first)
return it;
55 inline Pair *
Find(
const T &key)
57 for (uint i = 0; i < std::vector<Pair>::size(); i++) {
58 if (key == std::vector<Pair>::operator[](i).first)
return &std::vector<Pair>::operator[](i);
63 inline const Pair *End()
const
65 return std::vector<Pair>::data() + std::vector<Pair>::size();
70 return std::vector<Pair>::data() + std::vector<Pair>::size();
81 return this->
Find(key) != std::vector<Pair>::end();
91 return this->
Find(key) != this->End();
101 assert(pair >= std::vector<Pair>::data() && pair < this->End());
102 auto distance = pair - std::vector<Pair>::data();
103 std::vector<Pair>::erase(std::vector<Pair>::begin() + distance);
114 auto *pair = this->
Find(key);
115 if (pair == this->End())
return false;
127 inline bool Insert(
const T &key,
const U &data)
129 if (this->
Contains(key))
return false;
130 std::vector<Pair>::emplace_back(key, data);
142 for (uint i = 0; i < std::vector<Pair>::size(); i++) {
143 if (key == std::vector<Pair>::operator[](i).first)
return std::vector<Pair>::operator[](i).second;
145 Pair &n = std::vector<Pair>::emplace_back();