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>
void fl::HashMap< Key, T, Hash, KeyEqual, INLINED_COUNT >::rehash_inline_no_resize ( )
inlineprivate

Definition at line 490 of file hash_map.h.

490 {
491 // filter out tombstones and compact
492 size_t cap = _buckets.size();
493 size_t pos = 0;
494 // compact live elements to the left.
495 for (size_t i = 0; i < cap; ++i) {
496 if (is_occupied(i)) {
497 if (pos != i) {
499 mark_empty(i);
501 }
502 ++pos;
503 } else if (is_deleted(i)) {
504 mark_empty(i);
505 }
506 }
507
508 fl::bitset<1024> occupied; // Preallocate a bitset of size 1024
509 // swap the components, this will happen at most N times,
510 // use the occupied bitset to track which entries are occupied
511 // in the array rather than just copied in.
513 for (size_t i = 0; i < _size; ++i) {
514 const bool already_finished = occupied.test(i);
515 if (already_finished) {
516 continue;
517 }
518 auto &e = _buckets[i];
519 // FASTLED_ASSERT(e.state == EntryState::Occupied,
520 // "HashMap::rehash_inline_no_resize: invalid
521 // state");
522
524 if (idx == npos) {
525 // no more space
527 false, "HashMap::rehash_inline_no_resize: invalid index at "
528 << idx << " which is " << npos);
529 return;
530 }
531 // if idx < pos then we are moving the entry to a new location
533 "HashMap::rehash_inline_no_resize: invalid tmp");
534 if (idx >= _size) {
535 // directly copy it now
536 _buckets[idx] = e;
537 continue;
538 }
539 tmp = e;
540 occupied.set(idx);
541 _buckets[idx] = *tmp.ptr();
542 while (!tmp.empty()) {
543 // we have to find a place for temp.
544 // find new position for tmp.
545 auto key = tmp.ptr()->key;
546 size_t new_idx =
548 if (new_idx == npos) {
549 // no more space
551 false,
552 "HashMap::rehash_inline_no_resize: invalid index at "
553 << new_idx << " which is " << npos);
554 return;
555 }
556 occupied.set(new_idx);
557 if (new_idx < _size) {
558 // we have to swap the entry at new_idx with tmp
560 _buckets[new_idx] = *tmp.ptr();
561 tmp = tmp2;
562 } else {
563 // we can just move tmp to new_idx
564 _buckets[new_idx] = *tmp.ptr();
565 tmp.reset();
566 }
567 }
569 occupied.test(i),
570 "HashMap::rehash_inline_no_resize: invalid occupied at " << i);
572 !tmp, "HashMap::rehash_inline_no_resize: invalid tmp at " << i);
573 }
574 }
size_t _size
Definition hash_map.h:577
void mark_occupied(size_t idx)
Definition hash_map.h:302
static constexpr size_t npos
Definition hash_map.h:291
void mark_empty(size_t idx)
Definition hash_map.h:312
size_t find_unoccupied_index_using_bitset(const Key &key, const fl::bitset< 1024 > &occupied_set) const
Definition hash_map.h:428
bool is_occupied(size_t idx) const
Definition hash_map.h:294
bool empty() const
Definition hash_map.h:287
fl::vector_inlined< Entry, INLINED_COUNT > _buckets
Definition hash_map.h:576
bool is_deleted(size_t idx) const
Definition hash_map.h:296

Referenced by fl::HashMap< Key, T, Hash, KeyEqual >::insert().

+ Here is the caller graph for this function: