21 Value second = Value();
22 Pair(
const Key& k,
const Value& v) : first(k), second(v) {}
26 typedef typename VectorType::iterator iterator;
27 typedef typename VectorType::const_iterator const_iterator;
39 const_iterator begin()
const {
42 const_iterator end()
const {
46 iterator find(
const Key& key) {
47 for (
auto it = begin(); it != end(); ++it) {
48 if (it->first == key) {
55 const_iterator find(
const Key& key)
const {
56 for (
auto it = begin(); it != end(); ++it) {
57 if (it->first == key) {
66 bool get(
const Key& key, Value* value)
const {
67 const_iterator it = find(key);
75 Value get(
const Key& key,
bool* has=
nullptr)
const {
76 const_iterator it = find(key);
89 bool insert(
const Key& key,
const Value& value) {
90 iterator it = find(key);
92 if (data.size() < N) {
93 data.push_back(Pair(key, value));
100 bool update(
const Key& key,
const Value& value,
bool insert_if_missing =
true) {
101 iterator it = find(key);
105 }
else if (insert_if_missing) {
106 return insert(key, value);
111 Value& operator[](
const Key& key) {
112 iterator it = find(key);
116 data.push_back(Pair(key, Value()));
117 return data.back().second;
120 const Value& operator[](
const Key& key)
const {
121 const_iterator it = find(key);
125 static Value default_value;
126 return default_value;
129 bool next(
const Key& key, Key* next_key,
bool allow_rollover =
false)
const {
130 const_iterator it = find(key);
134 *next_key = it->first;
136 }
else if (allow_rollover && !empty()) {
137 *next_key = begin()->first;
144 bool prev(
const Key& key, Key* prev_key,
bool allow_rollover =
false)
const {
145 const_iterator it = find(key);
149 *prev_key = it->first;
151 }
else if (allow_rollover && !empty()) {
152 *prev_key = data[data.size() - 1].first;
161 constexpr size_t size()
const {
165 constexpr bool empty()
const {
170 constexpr size_t capacity()
const {
179 bool has(
const Key& it)
const {
180 return find(it) != end();