Commit dd46ba20 authored by Tiago Peixoto's avatar Tiago Peixoto

idx_map.hh: Fix random access

parent 7041c30f
......@@ -72,7 +72,10 @@ public:
T& operator[](const Key& key)
{
return insert(std::make_pair(key, T())).first->second;
auto iter = find(key);
if (iter == end())
iter = insert(std::make_pair(key, T())).first;
return iter->second;
}
iterator find(const Key& key)
......@@ -115,6 +118,9 @@ public:
const_iterator begin() const { return _items.begin(); }
const_iterator end() const { return _items.end(); }
size_t size() { return _items.size(); }
bool empty() { return _items.empty(); }
private:
std::vector<std::pair<Key,T>> _items;
std::vector<size_t> _pos;
......@@ -209,6 +215,9 @@ public:
const_iterator begin() const { return _items.begin(); }
const_iterator end() const { return _items.end(); }
size_t size() { return _items.size(); }
bool empty() { return _items.empty(); }
private:
std::vector<Key> _items;
std::vector<size_t> _pos;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment