FastLED
3.10.8
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::unordered_map
<
Key
, T,
Hash
, KeyEqual, INLINED_COUNT >::operator[]
(
const
Key
&
key
)
inline
Definition at line
681
of file
unordered_map.h
.
681
{
682
fl::size
idx
;
683
bool
is_new
;
684
685
fl::pair<fl::size, bool>
p
=
find_slot
(
key
);
686
idx
=
p
.first;
687
is_new
=
p
.second;
688
689
// Check if find_slot failed to find a valid slot (unordered_map is full)
690
if
(
idx
==
npos
()) {
691
// Need to resize to make room
692
if
(
needs_rehash
()) {
693
// if half the buckets are tombstones, rehash inline to prevent
694
// memory growth. Otherwise, double the size.
695
if
(
_tombstones
>=
_buckets
.size() / 2) {
696
rehash_inline_no_resize
();
697
}
else
{
698
rehash_internal
(
_buckets
.size() * 2);
699
}
700
}
else
{
701
// Force a rehash with double size if needs_rehash() doesn't detect the issue
702
rehash_internal
(
_buckets
.size() * 2);
703
}
704
705
// Try find_slot again after resize
706
p
=
find_slot
(
key
);
707
idx
=
p
.first;
708
is_new
=
p
.second;
709
710
// If still npos() after resize, allocation failed catastrophically
711
if
(
idx
==
npos
()) {
712
// This should never happen after a successful resize
713
static
T
default_value
{};
714
FASTLED_ASSERT
(
false
,
"unordered_map::operator[]: Failed to allocate after rehash"
);
715
return
default_value
;
716
}
717
}
718
719
if
(
is_new
) {
720
_buckets
[
idx
].key =
key
;
721
_buckets
[
idx
].value =
T
{};
722
mark_occupied
(
idx
);
723
++
_size
;
724
}
725
return
_buckets
[
idx
].value;
726
}
fl::unordered_map::rehash_internal
void rehash_internal(fl::size new_cap) FL_NO_EXCEPT
Definition
unordered_map.h:914
fl::unordered_map::needs_rehash
bool needs_rehash() const FL_NO_EXCEPT
Definition
unordered_map.h:319
fl::unordered_map::npos
static fl::size npos() FL_NO_EXCEPT
Definition
unordered_map.h:803
fl::unordered_map::_buckets
fl::vector_inlined< Entry, INLINED_COUNT > _buckets
Definition
unordered_map.h:1045
fl::unordered_map::_size
fl::size _size
Definition
unordered_map.h:1046
fl::unordered_map::mark_occupied
void mark_occupied(fl::size idx) FL_NO_EXCEPT
Definition
unordered_map.h:816
fl::unordered_map::rehash_inline_no_resize
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_NULL_DEREFERENCE void rehash_inline_no_resize() FL_NO_EXCEPT
Definition
unordered_map.h:939
fl::unordered_map::find_slot
pair< fl::size, bool > find_slot(const Key &key) const FL_NO_EXCEPT
Definition
unordered_map.h:848
fl::unordered_map::_tombstones
fl::size _tombstones
Definition
unordered_map.h:1047
fl::unordered_map
Definition
unordered_map.h:59
fl
unordered_map
Generated on Sun Oct 18 2026 00:57:09 for FastLED by
1.13.2