FastLED 3.9.15
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 1009 of file unordered_map.h.

1009 {
1010 // filter out tombstones and compact
1011 fl::size cap = _buckets.size();
1012 fl::size pos = 0;
1013 // compact live elements to the left.
1014 for (fl::size i = 0; i < cap; ++i) {
1015 if (is_occupied(i)) {
1016 if (pos != i) {
1018 mark_empty(i);
1020 }
1021 ++pos;
1022 } else if (is_deleted(i)) {
1023 mark_empty(i);
1024 }
1025 }
1026
1027 fl::bitset<1024> occupied; // Preallocate a bitset of size 1024
1028 // swap the components, this will happen at most N times,
1029 // use the occupied bitset to track which entries are occupied
1030 // in the array rather than just copied in.
1032 for (fl::size i = 0; i < _size; ++i) {
1033 const bool already_finished = occupied.test(i);
1034 if (already_finished) {
1035 continue;
1036 }
1037 auto &e = _buckets[i];
1038 // FASTLED_ASSERT(e.state == EntryState::Occupied,
1039 // "unordered_map::rehash_inline_no_resize: invalid
1040 // state");
1041
1043 if (idx == npos()) {
1044 // no more space
1046 false, "unordered_map::rehash_inline_no_resize: invalid index at "
1047 << idx << " which is " << npos());
1048 return;
1049 }
1050 // if idx < pos then we are moving the entry to a new location
1052 "unordered_map::rehash_inline_no_resize: invalid tmp");
1053 if (idx >= _size) {
1054 // directly move it now
1055 _buckets[idx] = fl::move(e);
1056 continue;
1057 }
1058 tmp = fl::move(e);
1059 occupied.set(idx);
1060 _buckets[idx] = fl::move(*tmp.ptr());
1061 while (!tmp.empty()) {
1062 // we have to find a place for temp.
1063 // find new position for tmp.
1064 auto key = tmp.ptr()->key;
1067 if (new_idx == npos()) {
1068 // no more space
1070 false,
1071 "unordered_map::rehash_inline_no_resize: invalid index at "
1072 << new_idx << " which is " << npos());
1073 return;
1074 }
1075 occupied.set(new_idx);
1076 if (new_idx < _size) {
1077 // we have to swap the entry at new_idx with tmp
1079 _buckets[new_idx] = fl::move(*tmp.ptr());
1080 tmp = fl::move(tmp2);
1081 } else {
1082 // we can just move tmp to new_idx
1083 _buckets[new_idx] = fl::move(*tmp.ptr());
1084 tmp.reset();
1085 }
1086 }
1088 occupied.test(i),
1089 "unordered_map::rehash_inline_no_resize: invalid occupied at " << i);
1091 tmp.empty(), "unordered_map::rehash_inline_no_resize: invalid tmp at " << i);
1092 }
1093 // Reset tombstones count since we've cleared all deleted entries
1094 _tombstones = 0;
1095 }
static fl::size npos()
void mark_occupied(fl::size idx)
bool is_deleted(fl::size idx) const
fl::vector_inlined< Entry, INLINED_COUNT > _buckets
bool empty() const
fl::size find_unoccupied_index_using_bitset(const Key &key, const fl::bitset< 1024 > &occupied_set) const
bool is_occupied(fl::size idx) const
void mark_empty(fl::size idx)
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition s16x16x4.h:28