mirror of
https://github.com/boostorg/functional.git
synced 2025-08-02 14:04:27 +02:00
Initial import of hash function headers - so that they can be used by
Boost.MultiIndex. [SVN r27819]
This commit is contained in:
122
include/boost/functional/detail/float_functions.hpp
Normal file
122
include/boost/functional/detail/float_functions.hpp
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
// (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)
|
||||||
|
|
||||||
|
#if !defined(BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_DETAIL_FLOAT_FUNCTIONS_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// The C++ standard requires that the C float functions are overloarded
|
||||||
|
// for float, double and long double in the std namespace, but some of the older
|
||||||
|
// library implementations don't support this. Some that don't supply the C99
|
||||||
|
// float functions (frexpf, frexpl, etc.) so those are used instead.
|
||||||
|
|
||||||
|
// This is just based on the compilers I've got access to, but it should
|
||||||
|
// do something sensible on most compilers.
|
||||||
|
|
||||||
|
#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
|
||||||
|
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1200
|
||||||
|
# define BOOST_HASH_USE_C99_FLOAT_FUNCS
|
||||||
|
# else
|
||||||
|
# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
|
||||||
|
# endif
|
||||||
|
#elif defined(_RWSTD_VER)
|
||||||
|
# define BOOST_HASH_USE_C99_FLOAT_FUNCS
|
||||||
|
# define BOOST_HASH_C99_NO_FLOAT_FUNCS
|
||||||
|
#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
|
||||||
|
# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
|
||||||
|
#elif defined(__STL_CONFIG_H)
|
||||||
|
// This might just be for gcc-2.95
|
||||||
|
// And cygwin might not have the C99 functions
|
||||||
|
# define BOOST_HASH_USE_C99_FLOAT_FUNCS
|
||||||
|
#elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER)
|
||||||
|
// Overloaded float functions were probably introduced at an earlier version.
|
||||||
|
# if defined(_CPPLIB_VER) && (_CPPLIB_VER >= 402)
|
||||||
|
# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
|
||||||
|
# else
|
||||||
|
# define BOOST_HASH_USE_C99_FLOAT_FUNCS
|
||||||
|
# endif
|
||||||
|
#elif defined(__DMC__)
|
||||||
|
# define BOOST_HASH_USE_C99_FLOAT_FUNCS
|
||||||
|
#else
|
||||||
|
# define BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
|
||||||
|
inline float call_ldexp(float v, int exp)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \
|
||||||
|
defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
|
||||||
|
return ldexp(v, exp);
|
||||||
|
#else
|
||||||
|
return ldexpf(v, exp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double call_ldexp(double v, int exp)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
return ldexp(v, exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline long double call_ldexp(long double v, int exp)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
|
||||||
|
return ldexp(v, exp);
|
||||||
|
#else
|
||||||
|
return ldexpl(v, exp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float call_frexp(float v, int* exp)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS) || \
|
||||||
|
defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
|
||||||
|
return frexp(v, exp);
|
||||||
|
#else
|
||||||
|
return frexpf(v, exp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double call_frexp(double v, int* exp)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
return frexp(v, exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline long double call_frexp(long double v, int* exp)
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
|
||||||
|
return frexp(v, exp);
|
||||||
|
#else
|
||||||
|
return frexpl(v, exp);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(BOOST_HASH_USE_C99_FLOAT_FUNCS)
|
||||||
|
#undef BOOST_HASH_USE_C99_FLOAT_FUNCS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS)
|
||||||
|
#undef BOOST_HASH_USE_OVERLOAD_FLOAT_FUNCS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(BOOST_HASH_C99_NO_FLOAT_FUNCS)
|
||||||
|
#undef BOOST_HASH_C99_NO_FLOAT_FUNCS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
25
include/boost/functional/hash.hpp
Normal file
25
include/boost/functional/hash.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// (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_HASH_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
#include <boost/functional/hash/pair.hpp>
|
||||||
|
#include <boost/functional/hash/vector.hpp>
|
||||||
|
#include <boost/functional/hash/list.hpp>
|
||||||
|
#include <boost/functional/hash/deque.hpp>
|
||||||
|
#include <boost/functional/hash/set.hpp>
|
||||||
|
#include <boost/functional/hash/map.hpp>
|
||||||
|
|
||||||
|
#endif
|
44
include/boost/functional/hash/Attic/deque.hpp
Normal file
44
include/boost/functional/hash/Attic/deque.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// (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_HASH_DEQUE_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_DEQUE_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
std::size_t hash_value(std::deque<T, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
struct call_hash<std::deque<T, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::deque<T, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
45
include/boost/functional/hash/Attic/list.hpp
Normal file
45
include/boost/functional/hash/Attic/list.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
// (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_HASH_LIST_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_LIST_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
std::size_t hash_value(std::list<T, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
struct call_hash<std::list<T, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::list<T, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
62
include/boost/functional/hash/Attic/map.hpp
Normal file
62
include/boost/functional/hash/Attic/map.hpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
// (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_HASH_MAP_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_MAP_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
#include <boost/functional/hash/pair.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
std::size_t hash_value(std::map<K, T, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
std::size_t hash_value(std::multimap<K, T, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
struct call_hash<std::map<K, T, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::map<K, T, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
struct call_hash<std::multimap<K, T, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::multimap<K, T, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
47
include/boost/functional/hash/Attic/pair.hpp
Normal file
47
include/boost/functional/hash/Attic/pair.hpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
// (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_HASH_PAIR_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_PAIR_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class A, class B>
|
||||||
|
std::size_t hash_value(std::pair<A, B> const& v)
|
||||||
|
{
|
||||||
|
std::size_t seed = 0;
|
||||||
|
hash_combine(seed, v.first);
|
||||||
|
hash_combine(seed, v.second);
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class A, class B>
|
||||||
|
struct call_hash<std::pair<A, B> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::pair<A, B> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
60
include/boost/functional/hash/Attic/set.hpp
Normal file
60
include/boost/functional/hash/Attic/set.hpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
// (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_HASH_SET_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_SET_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class K, class C, class A>
|
||||||
|
std::size_t hash_value(std::set<K, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class K, class C, class A>
|
||||||
|
std::size_t hash_value(std::multiset<K, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class K, class C, class A>
|
||||||
|
struct call_hash<std::set<K, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::set<K, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class C, class A>
|
||||||
|
struct call_hash<std::multiset<K, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::multiset<K, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
44
include/boost/functional/hash/Attic/vector.hpp
Normal file
44
include/boost/functional/hash/Attic/vector.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
// (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_HASH_VECTOR_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_VECTOR_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
std::size_t hash_value(std::vector<T, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
struct call_hash<std::vector<T, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::vector<T, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
44
include/boost/functional/hash/deque.hpp
Normal file
44
include/boost/functional/hash/deque.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// (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_HASH_DEQUE_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_DEQUE_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
std::size_t hash_value(std::deque<T, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
struct call_hash<std::deque<T, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::deque<T, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
225
include/boost/functional/hash/hash.hpp
Normal file
225
include/boost/functional/hash/hash.hpp
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
|
||||||
|
// (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_HASH_HASH_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_HASH_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/functional/detail/float_functions.hpp>
|
||||||
|
#include <boost/range/begin.hpp>
|
||||||
|
#include <boost/range/end.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
#if defined(__BORLANDC__)
|
||||||
|
// Borland complains about an ambiguous function overload
|
||||||
|
// when compiling boost::hash<bool>.
|
||||||
|
std::size_t hash_value(bool);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::size_t hash_value(int);
|
||||||
|
std::size_t hash_value(unsigned int);
|
||||||
|
std::size_t hash_value(long);
|
||||||
|
std::size_t hash_value(unsigned long);
|
||||||
|
|
||||||
|
template <class T> std::size_t hash_value(T*);
|
||||||
|
|
||||||
|
std::size_t hash_value(float v);
|
||||||
|
std::size_t hash_value(double v);
|
||||||
|
std::size_t hash_value(long double v);
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(__GNUC__, < 3) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
|
||||||
|
template <class Ch, class A>
|
||||||
|
std::size_t hash_value(std::basic_string<Ch, std::string_char_traits<Ch>, A> const&);
|
||||||
|
#else
|
||||||
|
template <class Ch, class A>
|
||||||
|
std::size_t hash_value(std::basic_string<Ch, std::char_traits<Ch>, A> const&);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template <class It> std::size_t hash_range(It first, It last);
|
||||||
|
template <class It> void hash_range(std::size_t&, It first, It last);
|
||||||
|
template <class Range> std::size_t hash_range(Range const& range);
|
||||||
|
template <class Range> void hash_range(std::size_t&, Range const& range);
|
||||||
|
|
||||||
|
template <class T> void hash_combine(std::size_t& seed, T const& v);
|
||||||
|
|
||||||
|
// Implementation
|
||||||
|
|
||||||
|
#if defined(__BORLANDC__)
|
||||||
|
inline std::size_t hash_value(bool v)
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(v);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline std::size_t hash_value(int v)
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t hash_value(unsigned int v)
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t hash_value(long v)
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t hash_value(unsigned long v)
|
||||||
|
{
|
||||||
|
return static_cast<std::size_t>(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementation by Alberto Barbati and Dave Harris.
|
||||||
|
template <class T> inline std::size_t hash_value(T* v)
|
||||||
|
{
|
||||||
|
std::size_t x = static_cast<std::size_t>(
|
||||||
|
reinterpret_cast<std::ptrdiff_t>(v));
|
||||||
|
return x + (x >> 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
// This allows boost::hash to be specialised for classes in the
|
||||||
|
// standard namespace. It appears that a strict two phase template
|
||||||
|
// implementation only finds overloads that are in the current
|
||||||
|
// namespace at the point of definition (at instantiation
|
||||||
|
// it only finds new overloads via. ADL on the dependant paramters or
|
||||||
|
// something like that).
|
||||||
|
template <class T>
|
||||||
|
struct call_hash
|
||||||
|
{
|
||||||
|
static std::size_t call(T const& v)
|
||||||
|
{
|
||||||
|
using namespace boost;
|
||||||
|
return hash_value(v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline void hash_combine(std::size_t& seed, T const& v)
|
||||||
|
{
|
||||||
|
seed ^= hash_detail::call_hash<T>::call(v)
|
||||||
|
+ 0x9e3779b9 + (seed<<6) + (seed>>2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
inline std::size_t hash_range(It first, It last)
|
||||||
|
{
|
||||||
|
std::size_t seed = 0;
|
||||||
|
|
||||||
|
for(; first != last; ++first)
|
||||||
|
{
|
||||||
|
hash_combine(seed, *first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class It>
|
||||||
|
inline void hash_range(std::size_t& seed, It first, It last)
|
||||||
|
{
|
||||||
|
for(; first != last; ++first)
|
||||||
|
{
|
||||||
|
hash_combine(seed, *first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
inline std::size_t hash_range(Range const& range)
|
||||||
|
{
|
||||||
|
return hash_range(boost::const_begin(range), boost::const_end(range));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
inline void hash_range(std::size_t& seed, Range const& range)
|
||||||
|
{
|
||||||
|
hash_range(seed, boost::const_begin(range), boost::const_end(range));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(__GNUC__, < 3) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
|
||||||
|
template <class Ch, class A>
|
||||||
|
inline std::size_t hash_value(std::basic_string<Ch, std::string_char_traits<Ch>, A> const& v)
|
||||||
|
#else
|
||||||
|
template <class Ch, class A>
|
||||||
|
inline std::size_t hash_value(std::basic_string<Ch, std::char_traits<Ch>, A> const& v)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
inline std::size_t float_hash_value(T v)
|
||||||
|
{
|
||||||
|
int exp;
|
||||||
|
v = boost::hash_detail::call_frexp(v, &exp);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return boost::hash_detail::float_hash_value(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t hash_value(double v)
|
||||||
|
{
|
||||||
|
return boost::hash_detail::float_hash_value(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t hash_value(long double v)
|
||||||
|
{
|
||||||
|
return boost::hash_detail::float_hash_value(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
// boost::hash
|
||||||
|
|
||||||
|
template <class T> struct hash
|
||||||
|
: std::unary_function<T, std::size_t>
|
||||||
|
{
|
||||||
|
std::size_t operator()(T const& val) const
|
||||||
|
{
|
||||||
|
return hash_detail::call_hash<T>::call(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
45
include/boost/functional/hash/list.hpp
Normal file
45
include/boost/functional/hash/list.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
// (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_HASH_LIST_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_LIST_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
std::size_t hash_value(std::list<T, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
struct call_hash<std::list<T, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::list<T, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
62
include/boost/functional/hash/map.hpp
Normal file
62
include/boost/functional/hash/map.hpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
// (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_HASH_MAP_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_MAP_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
#include <boost/functional/hash/pair.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
std::size_t hash_value(std::map<K, T, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
std::size_t hash_value(std::multimap<K, T, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
struct call_hash<std::map<K, T, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::map<K, T, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class T, class C, class A>
|
||||||
|
struct call_hash<std::multimap<K, T, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::multimap<K, T, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
47
include/boost/functional/hash/pair.hpp
Normal file
47
include/boost/functional/hash/pair.hpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
// (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_HASH_PAIR_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_PAIR_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class A, class B>
|
||||||
|
std::size_t hash_value(std::pair<A, B> const& v)
|
||||||
|
{
|
||||||
|
std::size_t seed = 0;
|
||||||
|
hash_combine(seed, v.first);
|
||||||
|
hash_combine(seed, v.second);
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class A, class B>
|
||||||
|
struct call_hash<std::pair<A, B> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::pair<A, B> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
60
include/boost/functional/hash/set.hpp
Normal file
60
include/boost/functional/hash/set.hpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
|
||||||
|
// (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_HASH_SET_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_SET_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class K, class C, class A>
|
||||||
|
std::size_t hash_value(std::set<K, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class K, class C, class A>
|
||||||
|
std::size_t hash_value(std::multiset<K, C, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class K, class C, class A>
|
||||||
|
struct call_hash<std::set<K, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::set<K, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class K, class C, class A>
|
||||||
|
struct call_hash<std::multiset<K, C, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::multiset<K, C, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
44
include/boost/functional/hash/vector.hpp
Normal file
44
include/boost/functional/hash/vector.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
// (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_HASH_VECTOR_HPP)
|
||||||
|
#define BOOST_FUNCTIONAL_HASH_VECTOR_HPP
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||||
|
# pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <boost/functional/hash/hash.hpp>
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
std::size_t hash_value(std::vector<T, A> const& v)
|
||||||
|
{
|
||||||
|
return hash_range(v.begin(), v.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
|
namespace hash_detail
|
||||||
|
{
|
||||||
|
template <class T, class A>
|
||||||
|
struct call_hash<std::vector<T, A> >
|
||||||
|
{
|
||||||
|
static std::size_t call(std::vector<T, A> const& val)
|
||||||
|
{
|
||||||
|
return boost::hash_value(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user