|
2 | 2 |
|
3 | 3 | namespace hud_test |
4 | 4 | { |
5 | | - struct collided_key |
6 | | - : hud_test::non_bitwise_type |
| 5 | + struct colliding_hasher |
7 | 6 | { |
8 | | - using super = hud_test::non_bitwise_type; |
9 | | - using super::super; |
10 | | - |
11 | | -#if defined(HD_COMPILER_GCC) |
12 | | - virtual constexpr ~collided_key() noexcept |
| 7 | + /** |
| 8 | + * Operator to hash the value and combine it with the current hasher value. |
| 9 | + * This function uses variadic templates to accept multiple arguments. |
| 10 | + * @tparam type_t Types of the arguments to hash. |
| 11 | + * @param values Arguments to hash. |
| 12 | + * @return A 64-bit hash value. |
| 13 | + */ |
| 14 | + [[nodiscard]] constexpr u64 operator()(const hud_test::non_bitwise_type &custom) noexcept |
13 | 15 | { |
14 | | - super::~super(); |
| 16 | + return hud::hash_64<i64> {}(custom.id() / 3); |
15 | 17 | } |
16 | | -#endif |
17 | | - }; |
18 | | -} // namespace hud_test |
19 | 18 |
|
20 | | -namespace hud |
21 | | -{ |
22 | | - template<> |
23 | | - struct hash_32<hud_test::collided_key> |
24 | | - { |
25 | | - [[nodiscard]] constexpr u32 operator()(const hud_test::collided_key &custom) const |
| 19 | + /** |
| 20 | + * Function to hash the value and combine it with the current hasher value. |
| 21 | + * This function uses variadic templates to accept multiple arguments. |
| 22 | + * @tparam type_t Types of the arguments to hash. |
| 23 | + * @param values Arguments to hash. |
| 24 | + * @return A 64-bit hash value. |
| 25 | + */ |
| 26 | + template<typename... type_t> |
| 27 | + [[nodiscard]] constexpr u64 hash(type_t &&...values) noexcept |
26 | 28 | { |
27 | | - return hud::hash_32<i32> {}(custom.id() / 3); |
| 29 | + return (*this)(hud::forward<type_t>(values)...); |
28 | 30 | } |
29 | 31 | }; |
30 | 32 |
|
31 | | - template<> |
32 | | - struct hash_64<hud_test::collided_key> |
33 | | - { |
34 | | - [[nodiscard]] constexpr u64 operator()(const hud_test::collided_key &custom) const |
35 | | - { |
36 | | - return hud::hash_64<i32> {}(custom.id() / 3); |
37 | | - } |
38 | | - }; |
39 | | - |
40 | | -} // namespace hud |
| 33 | +} // namespace hud_test |
41 | 34 |
|
42 | 35 | GTEST_TEST(hashmap, remove_non_trivial_type) |
43 | 36 | { |
@@ -202,9 +195,9 @@ GTEST_TEST(hashmap, remove_non_trivial_type) |
202 | 195 |
|
203 | 196 | GTEST_TEST(hashmap, remove_collided_key) |
204 | 197 | { |
205 | | - using key_type = hud_test::collided_key; |
| 198 | + using key_type = hud_test::non_bitwise_type; |
206 | 199 | using value_type = hud_test::non_bitwise_type; |
207 | | - using hashmap_type = hud::hashmap<key_type, value_type>; |
| 200 | + using hashmap_type = hud::hashmap<key_type, value_type, hud_test::colliding_hasher>; |
208 | 201 |
|
209 | 202 | // This test add 128 value remove every y elements check the map, |
210 | 203 | // then readd the removed elements and re check again the map by iterating over values |
|
0 commit comments