FastLED 3.10.9
Loading...
Searching...
No Matches

◆ rehash_inline_no_resize()

template<typename Key, typename T, typename Hash = Hash<Key>, typename KeyEqual = EqualTo<Key>, int INLINED_COUNT = FASTLED_HASHMAP_INLINED_COUNT>
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_NULL_DEREFERENCE void fl::unordered_map< Key, T, Hash, KeyEqual, INLINED_COUNT >::rehash_inline_no_resize ( )
inlineprivate

Definition at line 972 of file unordered_map.h.

972 {
973 // filter out tombstones and compact
974 fl::size cap = _buckets.size();
975 fl::size pos = 0;
976 // compact live elements to the left.
977 for (fl::size i = 0; i < cap; ++i) {
978 if (is_occupied(i)) {
979 if (pos != i) {
981 mark_empty(i);
983 }
984 ++pos;
985 } else if (is_deleted(i)) {
986 mark_empty(i);
987 }
988 }
989
990 fl::bitset<1024> occupied; // Preallocate a bitset of size 1024
991 // swap the components, this will happen at most N times,
992 // use the occupied bitset to track which entries are occupied
993 // in the array rather than just copied in.
995 for (fl::size i = 0; i < _size; ++i) {
996 const bool already_finished = occupied.test(i);
997 if (already_finished) {
998 continue;
999 }
1000 auto &e = _buckets[i];
1001 // FASTLED_ASSERT(e.state == EntryState::Occupied,
1002 // "unordered_map::rehash_inline_no_resize: invalid
1003 // state");
1004
1006 if (idx == npos()) {
1007 // no more space
1009 false, "unordered_map::rehash_inline_no_resize: invalid index");
1010 return;
1011 }
1012 // if idx < pos then we are moving the entry to a new location
1014 "unordered_map::rehash_inline_no_resize: invalid tmp");
1015 if (idx >= _size) {
1016 // directly move it now
1017 _buckets[idx] = fl::move(e);
1018 continue;
1019 }
1020 tmp = fl::move(e);
1021 occupied.set(idx);
1022 _buckets[idx] = fl::move(*tmp.ptr());
1023 while (!tmp.empty()) {
1024 // we have to find a place for temp.
1025 // find new position for tmp.
1026 auto key = tmp.ptr()->key;
1029 if (new_idx == npos()) {
1030 // no more space
1032 false,
1033 "unordered_map::rehash_inline_no_resize: invalid index");
1034 return;
1035 }
1036 occupied.set(new_idx);
1037 if (new_idx < _size) {
1038 // we have to swap the entry at new_idx with tmp
1040 _buckets[new_idx] = fl::move(*tmp.ptr());
1041 tmp = fl::move(tmp2);
1042 } else {
1043 // we can just move tmp to new_idx
1044 _buckets[new_idx] = fl::move(*tmp.ptr());
1045 tmp.reset();
1046 }
1047 }
1049 occupied.test(i),
1050 "unordered_map::rehash_inline_no_resize: invalid occupied");
1052 tmp.empty(), "unordered_map::rehash_inline_no_resize: invalid tmp");
1053 }
1054 // Reset tombstones count since we've cleared all deleted entries
1055 _tombstones = 0;
1056 }
bool is_occupied(fl::size idx) const FL_NO_EXCEPT
bool is_deleted(fl::size idx) 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
bool empty() const FL_NO_EXCEPT
void mark_empty(fl::size idx) FL_NO_EXCEPT
fl::size find_unoccupied_index_using_bitset(const Key &key, const fl::bitset< 1024 > &occupied_set) const FL_NO_EXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
Definition s16x16x4.h:30