FastLED 3.10.8
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 939 of file unordered_map.h.

939 {
940 // filter out tombstones and compact
941 fl::size cap = _buckets.size();
942 fl::size pos = 0;
943 // compact live elements to the left.
944 for (fl::size i = 0; i < cap; ++i) {
945 if (is_occupied(i)) {
946 if (pos != i) {
948 mark_empty(i);
950 }
951 ++pos;
952 } else if (is_deleted(i)) {
953 mark_empty(i);
954 }
955 }
956
957 fl::bitset<1024> occupied; // Preallocate a bitset of size 1024
958 // swap the components, this will happen at most N times,
959 // use the occupied bitset to track which entries are occupied
960 // in the array rather than just copied in.
962 for (fl::size i = 0; i < _size; ++i) {
963 const bool already_finished = occupied.test(i);
964 if (already_finished) {
965 continue;
966 }
967 auto &e = _buckets[i];
968 // FASTLED_ASSERT(e.state == EntryState::Occupied,
969 // "unordered_map::rehash_inline_no_resize: invalid
970 // state");
971
973 if (idx == npos()) {
974 // no more space
976 false, "unordered_map::rehash_inline_no_resize: invalid index");
977 return;
978 }
979 // if idx < pos then we are moving the entry to a new location
981 "unordered_map::rehash_inline_no_resize: invalid tmp");
982 if (idx >= _size) {
983 // directly move it now
985 continue;
986 }
987 tmp = fl::move(e);
988 occupied.set(idx);
989 _buckets[idx] = fl::move(*tmp.ptr());
990 while (!tmp.empty()) {
991 // we have to find a place for temp.
992 // find new position for tmp.
993 auto key = tmp.ptr()->key;
996 if (new_idx == npos()) {
997 // no more space
999 false,
1000 "unordered_map::rehash_inline_no_resize: invalid index");
1001 return;
1002 }
1003 occupied.set(new_idx);
1004 if (new_idx < _size) {
1005 // we have to swap the entry at new_idx with tmp
1007 _buckets[new_idx] = fl::move(*tmp.ptr());
1008 tmp = fl::move(tmp2);
1009 } else {
1010 // we can just move tmp to new_idx
1011 _buckets[new_idx] = fl::move(*tmp.ptr());
1012 tmp.reset();
1013 }
1014 }
1016 occupied.test(i),
1017 "unordered_map::rehash_inline_no_resize: invalid occupied");
1019 tmp.empty(), "unordered_map::rehash_inline_no_resize: invalid tmp");
1020 }
1021 // Reset tombstones count since we've cleared all deleted entries
1022 _tombstones = 0;
1023 }
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 move.h:30