MCPcopy Create free account
hub / github.com/FastLED/FastLED / insert_or_assign

Function insert_or_assign

src/fl/stl/unordered_map.h:415–439  ·  view source on GitHub ↗

insert_or_assign() - C++17: insert new element or update existing Returns pair where bool is true if inserted, false if updated

Source from the content-addressed store, hash-verified

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) {

Callers 1

insert_or_assignMethod · 0.85

Calls 7

needs_rehashFunction · 0.85
rehash_inline_no_resizeFunction · 0.85
rehash_internalFunction · 0.85
find_slotFunction · 0.85
mark_occupiedFunction · 0.85
iteratorClass · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected