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
) {
240
rehash_inline_no_resize
();
241
}
else
{
242
rehash
(
_buckets
.size() * 2);
243
}
244
}
245
fl::size
idx
;
246
bool
is_new
;
247
fl::pair<fl::size, bool>
p
=
find_slot
(
key
);
248
idx
=
p
.first;
249
is_new
=
p
.second;
250
if
(
is_new
) {
251
_buckets
[
idx
].key =
key
;
252
_buckets
[
idx
].value =
value
;
253
mark_occupied
(
idx
);
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::HashMap::_size
fl::size _size
Definition
hash_map.h:702
fl::HashMap::rehash_inline_no_resize
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_NULL_DEREFERENCE void rehash_inline_no_resize()
Definition
hash_map.h:612
fl::HashMap::npos
static fl::size npos()
Definition
hash_map.h:408
fl::HashMap::find_slot
pair< fl::size, bool > find_slot(const Key &key) const
Definition
hash_map.h:452
fl::HashMap::rehash
void rehash(fl::size new_cap)
Definition
hash_map.h:587
fl::HashMap::_tombstones
fl::size _tombstones
Definition
hash_map.h:703
fl::HashMap::_buckets
FL_DISABLE_WARNING_POP fl::vector_inlined< Entry, INLINED_COUNT > _buckets
Definition
hash_map.h:701
fl::HashMap::mark_occupied
void mark_occupied(fl::size idx)
Definition
hash_map.h:421
fl::HashMap::needs_rehash
bool needs_rehash() const
Definition
hash_map.h:229
fl::HashMap
Definition
hash_map.h:60
fl
HashMap
Generated on Fri Aug 22 2025 20:59:36 for FastLED by
1.13.2