mirror of
https://github.com/boostorg/functional.git
synced 2025-08-02 22:14:28 +02:00
Move the float hash function into its own header.
[SVN r32594]
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
#if !defined(BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP)
|
#if !defined(BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP)
|
||||||
#define BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP
|
#define BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
# pragma once
|
# pragma once
|
||||||
#endif
|
#endif
|
||||||
|
54
include/boost/functional/detail/hash_float.hpp
Normal file
54
include/boost/functional/detail/hash_float.hpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
// (C) Copyright Daniel James 2005.
|
||||||
|
// Use, modification and distribution are subject to the
|
||||||
|
// Boost Software License, Version 1.0. (See accompanying file
|
||||||
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
// Based on Peter Dimov's proposal
|
||||||
|
// http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
|
||||||
|
// issue 6.18.
|
||||||
|
|
||||||
|
#if !defined(BOOST_FUNCTIONAL_DETAIL_HASH_FLOAT_HEADER)
|
||||||
|
#define BOOST_FUNCTIONAL_DETAIL_HASH_FLOAT_HEADER
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/functional/detail/float_functions.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
inline std::size_t float_hash_value(T v)
|
||||||
|
{
|
||||||
|
int exp = 0;
|
||||||
|
errno = 0;
|
||||||
|
v = boost::hash_detail::call_frexp(v, &exp);
|
||||||
|
if(errno) return 0;
|
||||||
|
|
||||||
|
std::size_t seed = 0;
|
||||||
|
|
||||||
|
std::size_t const length
|
||||||
|
= (std::numeric_limits<T>::digits +
|
||||||
|
std::numeric_limits<int>::digits - 1)
|
||||||
|
/ std::numeric_limits<int>::digits;
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
v = boost::hash_detail::call_ldexp(v, std::numeric_limits<int>::digits);
|
||||||
|
int const part = static_cast<int>(v);
|
||||||
|
v -= part;
|
||||||
|
boost::hash_combine(seed, part);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::hash_combine(seed, exp);
|
||||||
|
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@@ -16,11 +16,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <boost/functional/hash_fwd.hpp>
|
#include <boost/functional/hash_fwd.hpp>
|
||||||
#include <cmath>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <boost/limits.hpp>
|
#include <boost/limits.hpp>
|
||||||
#include <boost/functional/detail/float_functions.hpp>
|
#include <boost/functional/detail/hash_float.hpp>
|
||||||
#include <boost/functional/detail/container_fwd.hpp>
|
#include <boost/functional/detail/container_fwd.hpp>
|
||||||
|
|
||||||
#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||||
@@ -244,37 +243,6 @@ namespace boost
|
|||||||
return hash_range(v.begin(), v.end());
|
return hash_range(v.begin(), v.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace hash_detail
|
|
||||||
{
|
|
||||||
template <class T>
|
|
||||||
inline std::size_t float_hash_value(T v)
|
|
||||||
{
|
|
||||||
int exp = 0;
|
|
||||||
errno = 0;
|
|
||||||
v = boost::hash_detail::call_frexp(v, &exp);
|
|
||||||
if(errno) return 0;
|
|
||||||
|
|
||||||
std::size_t seed = 0;
|
|
||||||
|
|
||||||
std::size_t const length
|
|
||||||
= (std::numeric_limits<T>::digits +
|
|
||||||
std::numeric_limits<int>::digits - 1)
|
|
||||||
/ std::numeric_limits<int>::digits;
|
|
||||||
|
|
||||||
for(std::size_t i = 0; i < length; ++i)
|
|
||||||
{
|
|
||||||
v = boost::hash_detail::call_ldexp(v, std::numeric_limits<int>::digits);
|
|
||||||
int const part = static_cast<int>(v);
|
|
||||||
v -= part;
|
|
||||||
boost::hash_combine(seed, part);
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::hash_combine(seed, exp);
|
|
||||||
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::size_t hash_value(float v)
|
inline std::size_t hash_value(float v)
|
||||||
{
|
{
|
||||||
return boost::hash_detail::float_hash_value(v);
|
return boost::hash_detail::float_hash_value(v);
|
||||||
|
Reference in New Issue
Block a user