FastLED
3.9.15
Loading...
Searching...
No Matches
◆
operator[]()
template<typename
Key
, typename T, typename
Hash
= Hash<Key>, typename KeyEqual = EqualTo<Key>, int INLINED_COUNT = FASTLED_HASHMAP_INLINED_COUNT>
T &
fl::HashMap
<
Key
, T,
Hash
, KeyEqual, INLINED_COUNT >::operator[]
(
const
Key
&
key
)
inline
Definition at line
355
of file
hash_map.h
.
355
{
356
fl::size
idx
;
357
bool
is_new
;
358
359
fl::pair<fl::size, bool>
p
=
find_slot
(
key
);
360
idx
=
p
.first;
361
is_new
=
p
.second;
362
363
// Check if find_slot failed to find a valid slot (HashMap is full)
364
if
(
idx
==
npos
()) {
365
// Need to resize to make room
366
if
(
needs_rehash
()) {
367
// if half the buckets are tombstones, rehash inline to prevent
368
// memory growth. Otherwise, double the size.
369
if
(
_tombstones
>=
_buckets
.size() / 2) {
370
rehash_inline_no_resize
();
371
}
else
{
372
rehash
(
_buckets
.size() * 2);
373
}
374
}
else
{
375
// Force a rehash with double size if needs_rehash() doesn't detect the issue
376
rehash
(
_buckets
.size() * 2);
377
}
378
379
// Try find_slot again after resize
380
p
=
find_slot
(
key
);
381
idx
=
p
.first;
382
is_new
=
p
.second;
383
384
// If still npos() after resize, something is seriously wrong
385
if
(
idx
==
npos
()) {
386
// This should never happen after a successful resize
387
static
T
default_value
{};
388
return
default_value
;
389
}
390
}
391
392
if
(
is_new
) {
393
_buckets
[
idx
].key =
key
;
394
_buckets
[
idx
].value =
T
{};
395
mark_occupied
(
idx
);
396
++
_size
;
397
}
398
return
_buckets
[
idx
].value;
399
}
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