FastLED 3.9.15
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages

◆ insert()

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 200 of file hash_map.h.

200 {
201 const bool will_rehash = needs_rehash();
202 if (will_rehash) {
203 // if half the buckets are tombstones, rehash inline to prevent
204 // memory spill over into the heap.
205 if (_tombstones > _size) {
207 } else {
208 rehash(_buckets.size() * 2);
209 }
210 }
211 size_t idx;
212 bool is_new;
214 idx = p.first;
215 is_new = p.second;
216 if (is_new) {
217 _buckets[idx].key = key;
218 _buckets[idx].value = value;
220 ++_size;
221 } else {
222 FASTLED_ASSERT(idx != npos, "HashMap::insert: invalid index at "
223 << idx << " which is " << npos);
224 _buckets[idx].value = value;
225 }
226 }
size_t _size
Definition hash_map.h:577
void mark_occupied(size_t idx)
Definition hash_map.h:302
static constexpr size_t npos
Definition hash_map.h:291
void rehash_inline_no_resize()
Definition hash_map.h:490
size_t _tombstones
Definition hash_map.h:578
void rehash(size_t new_cap)
Definition hash_map.h:468
pair< size_t, bool > find_slot(const Key &key) const
Definition hash_map.h:333
fl::vector_inlined< Entry, INLINED_COUNT > _buckets
Definition hash_map.h:576
bool needs_rehash() const
Definition hash_map.h:195

Referenced by fl::HashMap< Key, T, Hash, KeyEqual >::rehash().

+ Here is the caller graph for this function: