Revert hash_value for std::complex

This commit is contained in:
Peter Dimov
2022-05-29 21:58:19 +03:00
parent 7ad0365048
commit f08204e29a
2 changed files with 14 additions and 17 deletions

View File

@@ -86,8 +86,8 @@ namespace boost
{
static std::size_t fn( T v )
{
// The bias makes negative numbers that fit into a ssize_t hash to themselves
// E.g. hash_value( -4LL ) == (size_t)-4
// The bias makes negative numbers that fit into a ssize_t hash to themselves
// E.g. hash_value( -4LL ) == (size_t)-4
std::size_t const bias = (std::numeric_limits<std::size_t>::max)() / 4;
@@ -252,12 +252,11 @@ namespace boost
template <class T>
std::size_t hash_value( std::complex<T> const& v )
{
std::size_t seed = 0;
std::size_t re = boost::hash<T>()( v.real() );
std::size_t im = boost::hash<T>()( v.imag() );
boost::hash_combine( seed, v.real() );
boost::hash_combine( seed, v.imag() );
return seed;
im ^= re + ( im << 6 ) + ( im >> 2 );
return im;
}
// pair

View File

@@ -53,11 +53,11 @@ void generic_complex_tests(std::complex<T> v)
BOOST_HASH_TEST_NAMESPACE::hash<T> real_hasher;
T real = v.real();
// T imag = v.imag();
T imag = v.imag();
// BOOST_TEST(real_hasher(real) == complex_hasher(std::complex<T>(real)));
BOOST_TEST(real_hasher(real) == complex_hasher(std::complex<T>(real)));
if(real_hasher(real) == complex_hasher(v)) {
if(imag != 0 && real_hasher(real) == complex_hasher(v)) {
std::ostringstream os;
os<<"real_hasher("<<real<<") == complex_hasher("
<<v.real()<<" + "<<v.imag()<<"i) == "
@@ -89,10 +89,8 @@ void complex_integral_tests(Integer*)
generic_complex_tests(complex(Integer(-543),Integer(763)));
}
template<class T> void complex_grid_test()
template<class T> void complex_grid_test( short N )
{
short const N = 16;
std::set<std::size_t> hashes;
for( short i = 0; i < N; ++i )
@@ -122,10 +120,10 @@ int main()
complex_integral_tests((unsigned int*) 0);
complex_integral_tests((unsigned long*) 0);
complex_grid_test<int>();
complex_grid_test<float>();
complex_grid_test<double>();
complex_grid_test<long double>();
complex_grid_test<int>( 16 );
complex_grid_test<float>( 7 );
complex_grid_test<double>( 16 );
complex_grid_test<long double>( 16 );
return boost::report_errors();
}