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