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

Function insert

src/fl/stl/unordered_map.h:324–351  ·  view source on GitHub ↗

insert or overwrite - returns pair iterator points to element, bool is true if inserted, false if updated

Source from the content-addressed store, hash-verified

322 // insert or overwrite - returns pair<iterator, bool>
323 // iterator points to element, bool is true if inserted, false if updated
324 pair<iterator, bool> insert(const Key &key, const T &value) {
325 const bool will_rehash = needs_rehash();
326 if (will_rehash) {
327 // if half the buckets are tombstones, rehash inline to prevent
328 // memory spill over into the heap.
329 if (_tombstones > _size) {
330 rehash_inline_no_resize();
331 } else {
332 rehash_internal(_buckets.size() * 2);
333 }
334 }
335 fl::size idx;
336 bool is_new;
337 fl::pair<fl::size, bool> p = find_slot(key);
338 idx = p.first;
339 is_new = p.second;
340 if (is_new) {
341 _buckets[idx].key = key;
342 _buckets[idx].value = value;
343 mark_occupied(idx);
344 ++_size;
345 } else {
346 FASTLED_ASSERT(idx != npos(), "unordered_map::insert: invalid index at "
347 << idx << " which is " << npos());
348 _buckets[idx].value = value;
349 }
350 return {iterator(this, idx), is_new};
351 }
352
353 // Move version of insert - returns pair<iterator, bool>
354 // iterator points to element, bool is true if inserted, false if updated

Callers 4

unordered_mapFunction · 0.70
unordered_map.hFile · 0.70
emplaceFunction · 0.70
rehash_internalFunction · 0.70

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