Skip to content

Commit e6a87f2

Browse files
author
Julian LALU
committed
Improve hashmap
1 parent d800911 commit e6a87f2

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

interface/core/containers/hashset.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,19 @@ namespace hud
12711271
}
12721272

12731273
private:
1274+
template<typename key_type, typename u_key_type>
1275+
constexpr u64 compute_hash(const auto *slot)
1276+
{
1277+
if constexpr (hud::is_same_v<key_type, u_key_type>)
1278+
{
1279+
return hasher_type {}(slot->key());
1280+
}
1281+
else
1282+
{
1283+
return hasher_type {}(static_cast<key_type>(slot->key()));
1284+
}
1285+
}
1286+
12741287
template<typename u_storage_t, typename u_hasher_t, typename u_key_equal_t, typename u_allocator_t>
12751288
constexpr void copy_assign(const hashset_impl<u_storage_t, u_hasher_t, u_key_equal_t, u_allocator_t> &other) noexcept
12761289
{
@@ -1327,12 +1340,13 @@ namespace hud
13271340
// If we have elements to copy, copy them
13281341
if (count_ > 0)
13291342
{
1343+
// if constexpr (hud::is_same_v<key_type, typename u_storage_t::key_type>)
1344+
// {
13301345
control_type *control_full_or_sentinel = other.control_ptr_;
13311346
auto slot_full_or_sentinel = other.slot_ptr_;
13321347
while (control_full_or_sentinel != other.control_ptr_sentinel())
13331348
{
1334-
// Compute the hash
1335-
u64 hash {hasher_type {}(slot_full_or_sentinel->key())};
1349+
u64 hash {compute_hash<key_type, typename u_storage_t::key_type>(slot_full_or_sentinel)};
13361350
// Find H1 slot index
13371351
u64 h1 {H1(hash)};
13381352
usize slot_index {find_first_empty_or_deleted(control_ptr_, max_slot_count_, h1)};
@@ -1345,6 +1359,28 @@ namespace hud
13451359
slot_full_or_sentinel += full_or_sentinel - control_full_or_sentinel;
13461360
control_full_or_sentinel = full_or_sentinel;
13471361
}
1362+
// }
1363+
// else
1364+
// {
1365+
// control_type *control_full_or_sentinel = other.control_ptr_;
1366+
// auto slot_full_or_sentinel = other.slot_ptr_;
1367+
// while (control_full_or_sentinel != other.control_ptr_sentinel())
1368+
// {
1369+
// // Compute the hash
1370+
// u64 hash {hasher_type {}(static_cast<key_type>(slot_full_or_sentinel->key()))};
1371+
// // Find H1 slot index
1372+
// u64 h1 {H1(hash)};
1373+
// usize slot_index {find_first_empty_or_deleted(control_ptr_, max_slot_count_, h1)};
1374+
// // Save h2 in control h1 index
1375+
// control::set_h2(control_ptr_, slot_index, H2(hash), max_slot_count_);
1376+
// // Copy slot
1377+
// hud::memory::construct_object_at(slot_ptr_ + slot_index, *slot_full_or_sentinel);
1378+
1379+
// control_type *full_or_sentinel {control::skip_empty_or_deleted(control_full_or_sentinel + 1)};
1380+
// slot_full_or_sentinel += full_or_sentinel - control_full_or_sentinel;
1381+
// control_full_or_sentinel = full_or_sentinel;
1382+
// }
1383+
// }
13481384
}
13491385
}
13501386

0 commit comments

Comments
 (0)