mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-30 00:50:38 +08:00
building on linux
This commit is contained in:
Vendored
+27
-27
@@ -56,7 +56,7 @@ struct Hash
|
||||
template <class T>
|
||||
struct Hash<T *>
|
||||
{
|
||||
static size_t spp_log2 (size_t val) noexcept
|
||||
static size_t phmap_log2 (size_t val) noexcept
|
||||
{
|
||||
size_t res = 0;
|
||||
while (val > 1)
|
||||
@@ -69,7 +69,7 @@ struct Hash<T *>
|
||||
|
||||
inline size_t operator()(const T *__v) const noexcept
|
||||
{
|
||||
static const size_t shift = 3; // spp_log2(1 + sizeof(T)); // T might be incomplete!
|
||||
static const size_t shift = 3; // phmap_log2(1 + sizeof(T)); // T might be incomplete!
|
||||
const uintptr_t i = (const uintptr_t)__v;
|
||||
return static_cast<size_t>(i >> shift);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ struct Hash<T *>
|
||||
// fast and efficient for power of two table sizes where we always
|
||||
// consider the last bits.
|
||||
// ---------------------------------------------------------------
|
||||
inline size_t spp_mix_32(uint32_t a)
|
||||
inline size_t phmap_mix_32(uint32_t a)
|
||||
{
|
||||
a = a ^ (a >> 4);
|
||||
a = (a ^ 0xdeadbeef) + (a << 5);
|
||||
@@ -90,7 +90,7 @@ inline size_t spp_mix_32(uint32_t a)
|
||||
// More thorough scrambling as described in
|
||||
// https://gist.github.com/badboy/6267743
|
||||
// ----------------------------------------
|
||||
inline size_t spp_mix_64(uint64_t a)
|
||||
inline size_t phmap_mix_64(uint64_t a)
|
||||
{
|
||||
a = (~a) + (a << 21); // a = (a << 21) - a - 1;
|
||||
a = a ^ (a >> 24);
|
||||
@@ -103,108 +103,108 @@ inline size_t spp_mix_64(uint64_t a)
|
||||
}
|
||||
|
||||
template<class ArgumentType, class ResultType>
|
||||
struct spp_unary_function
|
||||
struct phmap_unary_function
|
||||
{
|
||||
typedef ArgumentType argument_type;
|
||||
typedef ResultType result_type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<bool> : public spp_unary_function<bool, size_t>
|
||||
struct Hash<bool> : public phmap_unary_function<bool, size_t>
|
||||
{
|
||||
inline size_t operator()(bool __v) const noexcept
|
||||
{ return static_cast<size_t>(__v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<char> : public spp_unary_function<char, size_t>
|
||||
struct Hash<char> : public phmap_unary_function<char, size_t>
|
||||
{
|
||||
inline size_t operator()(char __v) const noexcept
|
||||
{ return static_cast<size_t>(__v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<signed char> : public spp_unary_function<signed char, size_t>
|
||||
struct Hash<signed char> : public phmap_unary_function<signed char, size_t>
|
||||
{
|
||||
inline size_t operator()(signed char __v) const noexcept
|
||||
{ return static_cast<size_t>(__v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<unsigned char> : public spp_unary_function<unsigned char, size_t>
|
||||
struct Hash<unsigned char> : public phmap_unary_function<unsigned char, size_t>
|
||||
{
|
||||
inline size_t operator()(unsigned char __v) const noexcept
|
||||
{ return static_cast<size_t>(__v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<wchar_t> : public spp_unary_function<wchar_t, size_t>
|
||||
struct Hash<wchar_t> : public phmap_unary_function<wchar_t, size_t>
|
||||
{
|
||||
inline size_t operator()(wchar_t __v) const noexcept
|
||||
{ return static_cast<size_t>(__v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<int16_t> : public spp_unary_function<int16_t, size_t>
|
||||
struct Hash<int16_t> : public phmap_unary_function<int16_t, size_t>
|
||||
{
|
||||
inline size_t operator()(int16_t __v) const noexcept
|
||||
{ return spp_mix_32(static_cast<uint32_t>(__v)); }
|
||||
{ return phmap_mix_32(static_cast<uint32_t>(__v)); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<uint16_t> : public spp_unary_function<uint16_t, size_t>
|
||||
struct Hash<uint16_t> : public phmap_unary_function<uint16_t, size_t>
|
||||
{
|
||||
inline size_t operator()(uint16_t __v) const noexcept
|
||||
{ return spp_mix_32(static_cast<uint32_t>(__v)); }
|
||||
{ return phmap_mix_32(static_cast<uint32_t>(__v)); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<int32_t> : public spp_unary_function<int32_t, size_t>
|
||||
struct Hash<int32_t> : public phmap_unary_function<int32_t, size_t>
|
||||
{
|
||||
inline size_t operator()(int32_t __v) const noexcept
|
||||
{ return spp_mix_32(static_cast<uint32_t>(__v)); }
|
||||
{ return phmap_mix_32(static_cast<uint32_t>(__v)); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<uint32_t> : public spp_unary_function<uint32_t, size_t>
|
||||
struct Hash<uint32_t> : public phmap_unary_function<uint32_t, size_t>
|
||||
{
|
||||
inline size_t operator()(uint32_t __v) const noexcept
|
||||
{ return spp_mix_32(static_cast<uint32_t>(__v)); }
|
||||
{ return phmap_mix_32(static_cast<uint32_t>(__v)); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<int64_t> : public spp_unary_function<int64_t, size_t>
|
||||
struct Hash<int64_t> : public phmap_unary_function<int64_t, size_t>
|
||||
{
|
||||
inline size_t operator()(int64_t __v) const noexcept
|
||||
{ return spp_mix_64(static_cast<uint64_t>(__v)); }
|
||||
{ return phmap_mix_64(static_cast<uint64_t>(__v)); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<uint64_t> : public spp_unary_function<uint64_t, size_t>
|
||||
struct Hash<uint64_t> : public phmap_unary_function<uint64_t, size_t>
|
||||
{
|
||||
inline size_t operator()(uint64_t __v) const noexcept
|
||||
{ return spp_mix_64(static_cast<uint64_t>(__v)); }
|
||||
{ return phmap_mix_64(static_cast<uint64_t>(__v)); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<float> : public spp_unary_function<float, size_t>
|
||||
struct Hash<float> : public phmap_unary_function<float, size_t>
|
||||
{
|
||||
inline size_t operator()(float __v) const noexcept
|
||||
{
|
||||
// -0.0 and 0.0 should return same hash
|
||||
uint32_t *as_int = reinterpret_cast<uint32_t *>(&__v);
|
||||
return (__v == 0) ? static_cast<size_t>(0) : spp_mix_32(*as_int);
|
||||
return (__v == 0) ? static_cast<size_t>(0) : phmap_mix_32(*as_int);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Hash<double> : public spp_unary_function<double, size_t>
|
||||
struct Hash<double> : public phmap_unary_function<double, size_t>
|
||||
{
|
||||
inline size_t operator()(double __v) const noexcept
|
||||
{
|
||||
// -0.0 and 0.0 should return same hash
|
||||
uint64_t *as_int = reinterpret_cast<uint64_t *>(&__v);
|
||||
return (__v == 0) ? static_cast<size_t>(0) : spp_mix_64(*as_int);
|
||||
return (__v == 0) ? static_cast<size_t>(0) : phmap_mix_64(*as_int);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -232,7 +232,7 @@ template <class T> struct Combiner<T, 8>
|
||||
template <class T>
|
||||
inline void hash_combine(std::size_t& seed, T const& v)
|
||||
{
|
||||
spp_::Hash<T> hasher;
|
||||
phmap::Hash<T> hasher;
|
||||
Combiner<std::size_t, sizeof(std::size_t)> combiner;
|
||||
|
||||
combiner(seed, hasher(v));
|
||||
|
||||
Reference in New Issue
Block a user