Fixes to hash for long long, unsigned long long, float, double and long double. Credit Dave Zarzycki
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@145721 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f836d531b4
commit
62453ea71d
@ -1921,11 +1921,19 @@ struct _LIBCPP_VISIBLE hash<long long>
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
size_t operator()(long long __v) const _NOEXCEPT
|
size_t operator()(long long __v) const _NOEXCEPT
|
||||||
{
|
{
|
||||||
size_t __r = 0;
|
#ifdef __LP64__
|
||||||
const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
|
return __v;
|
||||||
for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
|
#else
|
||||||
__r ^= __p[__i];
|
union {
|
||||||
return __r;
|
long long __l;
|
||||||
|
struct {
|
||||||
|
int __a;
|
||||||
|
int __b;
|
||||||
|
} __s;
|
||||||
|
} __u;
|
||||||
|
__u.__l = __v;
|
||||||
|
return __u.__s.__a ^ __u.__s.__b;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1936,11 +1944,19 @@ struct _LIBCPP_VISIBLE hash<unsigned long long>
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
size_t operator()(unsigned long long __v) const _NOEXCEPT
|
size_t operator()(unsigned long long __v) const _NOEXCEPT
|
||||||
{
|
{
|
||||||
size_t __r = 0;
|
#ifdef __LP64__
|
||||||
const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
|
return __v;
|
||||||
for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
|
#else
|
||||||
__r ^= __p[__i];
|
union {
|
||||||
return __r;
|
unsigned long long __ul;
|
||||||
|
struct {
|
||||||
|
int __a;
|
||||||
|
int __b;
|
||||||
|
} __s;
|
||||||
|
} __u;
|
||||||
|
__u.__ul = __v;
|
||||||
|
return __u.__s.__a ^ __u.__s.__b;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1951,10 +1967,18 @@ struct _LIBCPP_VISIBLE hash<float>
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
size_t operator()(float __v) const _NOEXCEPT
|
size_t operator()(float __v) const _NOEXCEPT
|
||||||
{
|
{
|
||||||
|
union {
|
||||||
|
#ifdef __LP64__
|
||||||
|
double __f;
|
||||||
|
#else
|
||||||
|
float __f;
|
||||||
|
#endif
|
||||||
|
size_t __d;
|
||||||
|
} __u;
|
||||||
if (__v == 0)
|
if (__v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
|
__u.__f = __v;
|
||||||
return *__p;
|
return __u.__d;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1965,13 +1989,18 @@ struct _LIBCPP_VISIBLE hash<double>
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
size_t operator()(double __v) const _NOEXCEPT
|
size_t operator()(double __v) const _NOEXCEPT
|
||||||
{
|
{
|
||||||
|
union {
|
||||||
|
#ifdef __LP64__
|
||||||
|
double __f;
|
||||||
|
#else
|
||||||
|
float __f;
|
||||||
|
#endif
|
||||||
|
size_t __d;
|
||||||
|
} __u;
|
||||||
if (__v == 0)
|
if (__v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
size_t __r = 0;
|
__u.__f = __v;
|
||||||
const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
|
return __u.__d;
|
||||||
for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
|
|
||||||
__r ^= __p[__i];
|
|
||||||
return __r;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1982,13 +2011,18 @@ struct _LIBCPP_VISIBLE hash<long double>
|
|||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
size_t operator()(long double __v) const _NOEXCEPT
|
size_t operator()(long double __v) const _NOEXCEPT
|
||||||
{
|
{
|
||||||
|
union {
|
||||||
|
#ifdef __LP64__
|
||||||
|
double __f;
|
||||||
|
#else
|
||||||
|
float __f;
|
||||||
|
#endif
|
||||||
|
size_t __d;
|
||||||
|
} __u;
|
||||||
if (__v == 0)
|
if (__v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
size_t __r = 0;
|
__u.__f = __v;
|
||||||
const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
|
return __u.__d;
|
||||||
for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
|
|
||||||
__r ^= __p[__i];
|
|
||||||
return __r;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user