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
) {
269
rehash_inline_no_resize
();
270
}
else
{
271
rehash
(
_buckets
.size() * 2);
272
}
273
}
274
fl::size
idx
;
275
bool
is_new
;
276
fl::pair<fl::size, bool>
p
=
find_slot
(
key
);
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
);
282
mark_occupied
(
idx
);
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::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::move
constexpr remove_reference< T >::type && move(T &&t) noexcept
Definition
move.h:27
fl
HashMap
Generated on Fri Aug 22 2025 20:59:36 for FastLED by
1.13.2