Zen C++ Libraries
Zero-dependency re-usable components for C++
Loading...
Searching...
No Matches
seq_map.hpp
1#ifndef ZEN_SEQMAP_HPP
2#define ZEN_SEQMAP_HPP
3
4#include <vector>
5#include <list>
6
7#include "zen/config.hpp"
8#include "zen/hash_index.hpp"
9
10ZEN_NAMESPACE_START
11
12template<typename KeyT, typename ValueT>
13class seq_map {
14public:
15
16 using value_type = std::pair<KeyT, ValueT>;
17 using reference = value_type&;
18 using size_type = std::size_t;
19
20private:
21
22 struct entry {
23 value_type value;
24 };
25
26 std::list<value_type> entries;
28
29public:
30
31 using iterator = typename std::list<value_type>::iterator;
32 using const_iterator = typename std::list<value_type>::const_iterator;
33
34 void emplace(const KeyT& key, const ValueT& value) {
35 auto iter = entries.insert(entries.end(), std::make_pair(key, value));
36 index.insert(iter);
37 }
38
39 size_type size() {
40 return entries.size();
41 }
42
43 bool empty() const noexcept {
44 return entries.empty();
45 }
46
47 ValueT& operator[](const KeyT& key) {
48 return *index.lookup(key);
49 }
50
51 const ValueT& operator[](const KeyT& key) const {
52 return *index.lookup(key);
53 }
54
55 const_iterator cbegin() const {
56 return entries.cbegin();
57 }
58
59 const_iterator cend() const {
60 return entries.cend();
61 }
62
63};
64
65ZEN_NAMESPACE_END
66
67#endif // #ifndef ZEN_SEQMAP_HPP
Definition hash_index.hpp:93
Definition seq_map.hpp:13
Definition value.hpp:34