Skip to content

Commit f19507f

Browse files
author
Julian LALU
committed
Update hashset_implt
1 parent 6f2ee40 commit f19507f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

interface/core/containers/hashset.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -743,22 +743,20 @@ namespace hud
743743
return slot_index;
744744
}
745745

746-
constexpr void grow_capacity(usize slot_count) noexcept
746+
constexpr void grow_capacity(usize new_max_slot_count) noexcept
747747
{
748-
hud::check(slot_count > max_slot_count_ && "Grow need a bigger value");
748+
hud::check(new_max_slot_count > max_slot_count_ && "Grow need a bigger value");
749749
hud::check(hud::bits::is_valid_power_of_two_mask(max_slot_count_) && "Not a mask");
750750

751-
usize new_max_slot_count_ = slot_count;
752-
753751
// Create the buffer with control and slots
754752
// Slots are aligned on alignof(slot_type)
755753

756754
// We cloned size of a group - 1 because we never reach the last cloned bytes
757755
constexpr const usize num_cloned_bytes = control::COUNT_CLONED_BYTE;
758756
// Control size is the number of slot + sentinel + number of cloned bytes
759-
const usize control_size = new_max_slot_count_ + 1 + num_cloned_bytes;
757+
const usize control_size = new_max_slot_count + 1 + num_cloned_bytes;
760758
const uptr aligned_control_size = hud::memory::align_address(control_size, sizeof(slot_type));
761-
const usize aligned_allocation_size = aligned_control_size + new_max_slot_count_ * sizeof(slot_type);
759+
const usize aligned_allocation_size = aligned_control_size + new_max_slot_count * sizeof(slot_type);
762760

763761
// Allocate the buffer that will contains controls and aligned slots
764762
memory_allocation_type allocation = allocator_.template allocate<slot_type>(aligned_allocation_size);
@@ -769,11 +767,11 @@ namespace hud
769767
hud::check(hud::memory::is_pointer_aligned(new_slot_ptr, alignof(slot_type)));
770768

771769
// Update number of slot we should put into the table before a resizing rehash
772-
free_slot_before_grow_ = max_slot_before_grow(new_max_slot_count_) - count_;
770+
free_slot_before_grow_ = max_slot_before_grow(new_max_slot_count) - count_;
773771

774772
// Reset control metadata
775773
hud::memory::set(new_control_ptr, control_size, empty_byte);
776-
new_control_ptr[new_max_slot_count_] = sentinel_byte;
774+
new_control_ptr[new_max_slot_count] = sentinel_byte;
777775

778776
// If we have elements, insert them to the new buffer
779777
if (count_ > 0)
@@ -786,9 +784,9 @@ namespace hud
786784
u64 hash = hasher_type {}(slot.key());
787785
// Find H1 slot index
788786
u64 h1 = H1(hash);
789-
usize slot_index = find_first_empty_or_deleted(new_control_ptr, new_max_slot_count_, h1);
787+
usize slot_index = find_first_empty_or_deleted(new_control_ptr, new_max_slot_count, h1);
790788
// Save h2 in control h1 index
791-
control::set_h2(new_control_ptr, slot_index, H2(hash), new_max_slot_count_);
789+
control::set_h2(new_control_ptr, slot_index, H2(hash), new_max_slot_count);
792790
// Move old slot to new slot
793791
hud::memory::move_or_copy_construct_then_destroy(new_slot_ptr + slot_index, hud::move(slot));
794792
}
@@ -798,7 +796,7 @@ namespace hud
798796

799797
control_ptr_ = new_control_ptr;
800798
slot_ptr_ = new_slot_ptr;
801-
max_slot_count_ = new_max_slot_count_;
799+
max_slot_count_ = new_max_slot_count;
802800
}
803801

804802
[[nodiscard]] constexpr usize free_slot_before_grow() const noexcept

0 commit comments

Comments
 (0)