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

◆ insert() [1/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 ( const Key & key,
const T & value )
inline

Definition at line 234 of file hash_map.h.

234 {
235 const bool will_rehash = needs_rehash();
236 if (will_rehash) {
237 // if half the buckets are tombstones, rehash inline to prevent
238 // memory spill over into the heap.
239 if (_tombstones > _size) {
241 } else {
242 rehash(_buckets.size() * 2);
243 }
244 }
246 bool is_new;
248 idx = p.first;
249 is_new = p.second;
250 if (is_new) {
251 _buckets[idx].key = key;
252 _buckets[idx].value = value;
254 ++_size;
255 } else {
256 FASTLED_ASSERT(idx != npos(), "HashMap::insert: invalid index at "
257 << idx << " which is " << npos());
258 _buckets[idx].value = value;
259 }
260 }
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