FastLED 3.10.9
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 683 of file unordered_map.h.

683 {
685 bool is_new;
686
688 idx = p.first;
689 is_new = p.second;
690
691 // Check if find_slot failed to find a valid slot (unordered_map is full)
692 if (idx == npos()) {
693 // Need to resize to make room
694 if (needs_rehash()) {
695 // if half the buckets are tombstones, rehash inline to prevent
696 // memory growth. Otherwise, double the size.
697 if (_tombstones >= _buckets.size() / 2) {
699 } else {
700 rehash_internal(_buckets.size() * 2);
701 }
702 } else {
703 // Force a rehash with double size if needs_rehash() doesn't detect the issue
704 rehash_internal(_buckets.size() * 2);
705 }
706
707 // Try find_slot again after resize
708 p = find_slot(key);
709 idx = p.first;
710 is_new = p.second;
711
712 // If still npos() after resize, allocation failed catastrophically
713 if (idx == npos()) {
714 // This should never happen after a successful resize
715 static T default_value{};
716 FASTLED_ASSERT(false, "unordered_map::operator[]: Failed to allocate after rehash");
717 return default_value;
718 }
719 }
720
721 if (is_new) {
722 _buckets[idx].key = key;
723 _buckets[idx].value = T{};
725 ++_size;
726 }
727 return _buckets[idx].value;
728 }
void rehash_internal(fl::size new_cap) FL_NO_EXCEPT
bool needs_rehash() const FL_NO_EXCEPT
static fl::size npos() FL_NO_EXCEPT
fl::vector_inlined< Entry, INLINED_COUNT > _buckets
void mark_occupied(fl::size idx) FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_NULL_DEREFERENCE void rehash_inline_no_resize() FL_NO_EXCEPT
pair< fl::size, bool > find_slot(const Key &key) const FL_NO_EXCEPT