Skip to content

Commit 69b65c9

Browse files
committed
Rewrite hash_combined to be self contained., and entirely generic. As some compiler versions don't support constexpr arrays.
1 parent 5a19a2c commit 69b65c9

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

cpp/include/versioned/versioned.hpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,39 +64,25 @@ constexpr N masked_max(U value)
6464
}
6565

6666
// Simple hash values combine.
67-
template <int C>
68-
struct hash_combine_val
69-
{};
70-
template <>
71-
struct hash_combine_val<4>
72-
{
73-
static constexpr char shift[] = { 15, 6, 8, 4, 5 };
74-
};
75-
template <>
76-
struct hash_combine_val<8>
77-
{
78-
static constexpr char shift[] = { 30, 13, 16, 8, 11 };
79-
};
80-
8167
template <class T, class... N>
8268
T hash_combine(T seed, N... an)
8369
{
84-
using h = hash_combine_val<sizeof(T)>;
8570
T args[] = { an... };
8671
// Init.
8772
T result = seed;
8873
// Combine.
8974
for (auto a : args)
9075
{
9176
result ^= a + masked_max<T>(3772387269305686495)
92-
+ (result << h::shift[0]) + (result >> h::shift[1]);
77+
+ (result << (30 * 2 / sizeof(T)))
78+
+ (result >> (13 * 2 / sizeof(T)));
9379
}
9480
// Mix.
95-
result ^= (result >> h::shift[2]);
81+
result ^= (result >> (16 * 2 / sizeof(T)));
9682
result *= masked_max<T>(448100074733706);
97-
result ^= (result << h::shift[3]);
83+
result ^= (result << (8 * 2 / sizeof(T)));
9884
result += masked_max<T>(190056597654806);
99-
result ^= (result >> h::shift[4]);
85+
result ^= (result >> (11 * 2 / sizeof(T)));
10086
return result;
10187
}
10288

0 commit comments

Comments
 (0)