23 #include <unordered_map>
34 std::unordered_map<std::string , size_t> m_map;
35 std::vector<T> m_vector;
38 bool hasKey(
const std::string& key)
const {
39 auto iter = m_map.find(key);
40 if (iter == m_map.end())
47 void insert(std::string key, T value) {
49 auto iter = m_map.find( key );
50 size_t index = iter->second;
51 m_vector[index] = value;
53 size_t index = m_vector.size();
54 m_vector.push_back( value );
55 m_map.insert( std::pair<std::string, size_t>(key , index));
60 T
get(
const std::string& key)
const {
61 auto iter = m_map.find( key );
62 if (iter == m_map.end())
63 throw std::invalid_argument(
"Key not found");
65 size_t index = iter->second;
71 T
get(
size_t index)
const {
72 if (index >= m_vector.size())
73 throw std::invalid_argument(
"Invalid index");
74 return m_vector[index];
79 return m_vector.size();
83 typename std::vector<T>::const_iterator
begin()
const {
84 return m_vector.begin();
88 typename std::vector<T>::const_iterator
end()
const {
89 return m_vector.end();
Definition: OrderedMap.hpp:32
std::vector< T >::const_iterator begin() const
Definition: OrderedMap.hpp:83
std::vector< T >::const_iterator end() const
Definition: OrderedMap.hpp:88
size_t size() const
Definition: OrderedMap.hpp:78
void insert(std::string key, T value)
Definition: OrderedMap.hpp:47
bool hasKey(const std::string &key) const
Definition: OrderedMap.hpp:38