insert_or_assign() - C++17: insert new element or update existing Returns pair where bool is true if inserted, false if updated
| 413 | // insert_or_assign() - C++17: insert new element or update existing |
| 414 | // Returns pair<iterator, bool> where bool is true if inserted, false if updated |
| 415 | pair<iterator, bool> insert_or_assign(const Key &key, T &&value) { |
| 416 | const bool will_rehash = needs_rehash(); |
| 417 | if (will_rehash) { |
| 418 | if (_tombstones > _size) { |
| 419 | rehash_inline_no_resize(); |
| 420 | } else { |
| 421 | rehash_internal(_buckets.size() * 2); |
| 422 | } |
| 423 | } |
| 424 | fl::size idx; |
| 425 | bool is_new; |
| 426 | fl::pair<fl::size, bool> p = find_slot(key); |
| 427 | idx = p.first; |
| 428 | is_new = p.second; |
| 429 | if (is_new) { |
| 430 | _buckets[idx].key = key; |
| 431 | _buckets[idx].value = fl::move(value); |
| 432 | mark_occupied(idx); |
| 433 | ++_size; |
| 434 | } else { |
| 435 | FASTLED_ASSERT(idx != npos(), "unordered_map::insert_or_assign: invalid index"); |
| 436 | _buckets[idx].value = fl::move(value); |
| 437 | } |
| 438 | return {iterator(this, idx), is_new}; |
| 439 | } |
| 440 | |
| 441 | // insert_or_assign() with move key - C++17 |
| 442 | pair<iterator, bool> insert_or_assign(Key &&key, T &&value) { |
no test coverage detected