Skip to content

Commit 33b33c6

Browse files
author
Julian LALU
committed
hashmap now produce the same hash as abseil modified implementation
1 parent b8e3c5f commit 33b33c6

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

interface/core/containers/hashmap.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@ namespace hud
1717
{
1818
using key_type = key_t;
1919

20-
// [[nodiscard]] u64 operator()(const key_type &key) const noexcept
21-
// {
22-
// return hud::hash_64(key);
23-
// }
20+
/** The hasher hash ansichar and wchar with their size. */
21+
template<typename... type_t>
22+
[[nodiscard]] constexpr hasher_64 &operator()(const ansichar *value, const usize length) noexcept
23+
{
24+
return hud::hasher_64::hash(value, length).hash(reinterpret_cast<const ansichar *>(&length), sizeof(length));
25+
}
26+
27+
/** The hasher hash ansichar and wchar with their size. */
28+
template<typename... type_t>
29+
[[nodiscard]] constexpr hasher_64 &operator()(const ansichar *value) noexcept
30+
{
31+
return (*this)(value, hud::cstring::length(value));
32+
}
2433
};
2534

2635
template<typename key_t> struct default_equal
@@ -103,7 +112,7 @@ namespace hud
103112

104113
template<
105114
typename slot_t,
106-
typename hash_t,
115+
typename hasher_t,
107116
typename key_equal_t,
108117
typename allocator_t>
109118
class hashmap_impl
@@ -116,7 +125,7 @@ namespace hud
116125
/** Type of the value. */
117126
using value_type = typename slot_type::value_type;
118127
/** Type of the hash function. */
119-
using hash_type = hash_t;
128+
using hasher_type = hasher_t;
120129
/****/
121130
using iterator = hud::details::hashmap::iterator<slot_type>;
122131

@@ -136,7 +145,7 @@ namespace hud
136145
{
137146
// TODO: prefetch control bloc
138147
// Hash the key
139-
u64 hash = hash_type {}(key);
148+
u64 hash = hasher_type {}(key);
140149
return hud::nullopt;
141150
}
142151

@@ -175,7 +184,7 @@ namespace hud
175184

176185
public:
177186
/** Type of the hash function. */
178-
using typename super::hash_type;
187+
using typename super::hasher_type;
179188
/** Type of the key. */
180189
using typename super::key_type;
181190
/** Type of the value. */

interface/core/containers/hashset.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ namespace hud
1818

1919
template<
2020
typename value_t,
21-
typename hash_t = details::hashmap::default_hasher<value_t>,
21+
typename hasher_type = details::hashmap::default_hasher<value_t>,
2222
typename key_equal_t = details::hashmap::default_equal<value_t>,
2323
typename allocator_t = heap_allocator>
2424
class hashset
25-
: details::hashmap::hashmap_impl<details::hashset::slot<value_t>, hash_t, key_equal_t, allocator_t>
25+
: details::hashmap::hashmap_impl<details::hashset::slot<value_t>, hasher_type, key_equal_t, allocator_t>
2626
{
2727
private:
28-
using super = details::hashmap::hashmap_impl<details::hashset::slot<value_t>, hash_t, key_equal_t, allocator_t>;
28+
using super = details::hashmap::hashmap_impl<details::hashset::slot<value_t>, hasher_type, key_equal_t, allocator_t>;
2929

3030
public:
3131
/** Type of the hash function. */
32-
using typename super::hash_type;
32+
using typename super::hasher_type;
3333
/** Type of the value. */
3434
using typename super::value_type;
3535

0 commit comments

Comments
 (0)