FastLED 3.9.15
Loading...
Searching...
No Matches

◆ insert() [2/2]

template<typename Key, typename T, typename Hash = Hash<Key>, typename KeyEqual = EqualTo<Key>, int INLINED_COUNT = FASTLED_HASHMAP_INLINED_COUNT>
void fl::HashMap< Key, T, Hash, KeyEqual, INLINED_COUNT >::insert ( Key && key,
T && value )
inline

Definition at line 263 of file hash_map.h.

263 {
264 const bool will_rehash = needs_rehash();
265 if (will_rehash) {
266 // if half the buckets are tombstones, rehash inline to prevent
267 // memory spill over into the heap.
268 if (_tombstones > _size) {
270 } else {
271 rehash(_buckets.size() * 2);
272 }
273 }
275 bool is_new;
277 idx = p.first;
278 is_new = p.second;
279 if (is_new) {
280 _buckets[idx].key = fl::move(key);
281 _buckets[idx].value = fl::move(value);
283 ++_size;
284 } else {
285 FASTLED_ASSERT(idx != npos(), "HashMap::insert: invalid index at "
286 << idx << " which is " << npos());
287 _buckets[idx].value = fl::move(value);
288 }
289 }
fl::size _size
Definition hash_map.h:702
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_NULL_DEREFERENCE void rehash_inline_no_resize()
Definition hash_map.h:612
static fl::size npos()
Definition hash_map.h:408
pair< fl::size, bool > find_slot(const Key &key) const
Definition hash_map.h:452
void rehash(fl::size new_cap)
Definition hash_map.h:587
fl::size _tombstones
Definition hash_map.h:703
FL_DISABLE_WARNING_POP fl::vector_inlined< Entry, INLINED_COUNT > _buckets
Definition hash_map.h:701
void mark_occupied(fl::size idx)
Definition hash_map.h:421
bool needs_rehash() const
Definition hash_map.h:229
constexpr remove_reference< T >::type && move(T &&t) noexcept
Definition move.h:27