34 typedef typename VectorType::iterator iterator;
35 typedef typename VectorType::const_iterator const_iterator;
47 const_iterator begin()
const {
50 const_iterator end()
const {
54 iterator find(
const Key& key) {
55 for (
auto it = begin(); it != end(); ++it) {
56 if (it->first == key) {
63 const_iterator find(
const Key& key)
const {
64 for (
auto it = begin(); it != end(); ++it) {
65 if (it->first == key) {
72 template<
typename Less>
73 iterator lowest(Less less_than = Less()) {
74 iterator lowest = end();
75 for (iterator it = begin(); it != end(); ++it) {
76 if (lowest == end() || less_than(it->first, lowest->first)) {
83 template<
typename Less>
84 const_iterator lowest(Less less_than = Less())
const {
85 const_iterator lowest = end();
86 for (const_iterator it = begin(); it != end(); ++it) {
87 if (lowest == end() || less_than(it->first, lowest->first)) {
94 template<
typename Less>
95 iterator highest(Less less_than = Less()) {
96 iterator highest = end();
97 for (iterator it = begin(); it != end(); ++it) {
98 if (highest == end() || less_than(highest->first, it->first)) {
105 template<
typename Less>
106 const_iterator highest(Less less_than = Less())
const {
107 const_iterator highest = end();
108 for (const_iterator it = begin(); it != end(); ++it) {
109 if (highest == end() || less_than(highest->first, it->first)) {
118 bool get(
const Key& key, Value* value)
const {
119 const_iterator it = find(key);
127 Value get(
const Key& key,
bool* has=
nullptr)
const {
128 const_iterator it = find(key);
142 iterator it = find(key);
145 *result = InsertResult::kExists;
150 if (data.size() < N) {
151 data.push_back(
PairKV(key, value));
153 *result = InsertResult::kInserted;
156 return {
true, data.end() - 1};
159 *result = InsertResult::kMaxSize;
162 return {
false, end()};
165 bool update(
const Key& key,
const Value& value,
bool insert_if_missing =
true) {
166 iterator it = find(key);
170 }
else if (insert_if_missing) {
171 return insert(key, value).first;
176 Value& operator[](
const Key& key) {
177 iterator it = find(key);
181 data.push_back(
PairKV(key, Value()));
182 return data.back().second;
185 const Value& operator[](
const Key& key)
const {
186 const_iterator it = find(key);
190 static Value default_value;
191 return default_value;
194 bool next(
const Key& key,
Key* next_key,
bool allow_rollover =
false)
const {
195 const_iterator it = find(key);
199 *next_key = it->first;
201 }
else if (allow_rollover && !empty()) {
202 *next_key = begin()->first;
209 bool prev(
const Key& key,
Key* prev_key,
bool allow_rollover =
false)
const {
210 const_iterator it = find(key);
214 *prev_key = it->first;
216 }
else if (allow_rollover && !empty()) {
217 *prev_key = data[data.size() - 1].first;
226 constexpr size_t size()
const {
230 constexpr bool empty()
const {
235 constexpr size_t capacity()
const {
244 bool has(
const Key& it)
const {
245 return find(it) != end();
248 bool contains(
const Key& key)
const {
263 Pair(
const Key& k =
Key(),
const Value& v = Value())
264 : first(k), second(v) {}
269 bool operator()(
const Pair& a,
const Pair& b)
const {
270 return less(a.first, b.first);
280 typedef Pair value_type;
283 : data(PairLess{less}) {
286 void setMaxSize(
size_t n) {
290 void reserve(
size_t n) {
294 bool insert(
const Key& key,
const Value& value, InsertResult* result =
nullptr) {
295 return data.insert(Pair(key, value), result);
298 void update(
const Key& key,
const Value& value) {
299 if (!insert(key, value)) {
306 data.swap(other.data);
309 Value& at(
const Key& key) {
314 bool has(
const Key& key)
const {
315 return data.has(Pair(key));
318 bool contains(
const Key& key)
const {
323 if (size() != other.size()) {
327 it != end(); ++it, ++other_it) {
328 if (it->first != other_it->first || it->second != other_it->second) {
336 return !(*
this == other);
339 size_t size()
const {
return data.size(); }
340 bool empty()
const {
return data.empty(); }
341 bool full()
const {
return data.full(); }
342 size_t capacity()
const {
return data.capacity(); }
343 void clear() { data.clear(); }
346 iterator begin() {
return data.begin(); }
347 iterator end() {
return data.end(); }
352 return data.find(Pair(key));
355 return data.find(Pair(key));
358 bool erase(
const Key& key) {
359 return data.erase(Pair(key));
362 return data.erase(it);
366 return data.lower_bound(Pair(key));
370 return data.lower_bound(Pair(key));
375 if (it != end() && it->first == key) {
383 if (it != end() && it->first == key) {
389 Pair& front() {
return data.front(); }
390 const Pair& front()
const {
return data.front(); }
391 Pair& back() {
return data.back(); }
392 const Pair& back()
const {
return data.back(); }
395 Value& operator[](
const Key& key) {
400 Pair pair(key, Value());
401 bool ok = data.insert(pair);
402 FASTLED_ASSERT(ok,
"Failed to insert into SortedHeapMap");
403 return data.find(pair)->second;