Update of /cvsroot/boost/boost/boost/functional/hash
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv18354
Modified Files:
hash.hpp
Log Message:
Add support for long long to Boost.Hash.
Index: hash.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/functional/hash/hash.hpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- hash.hpp 6 Jun 2006 08:14:23 -0000 1.29
+++ hash.hpp 6 Jun 2006 20:13:33 -0000 1.30
@@ -10,6 +10,10 @@
#if !defined(BOOST_FUNCTIONAL_HASH_HASH_HPP)
#define BOOST_FUNCTIONAL_HASH_HASH_HPP
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
#include <boost/functional/hash_fwd.hpp>
#include <functional>
#include <boost/functional/detail/hash_float.hpp>
@@ -41,6 +45,11 @@
std::size_t hash_value(long);
std::size_t hash_value(unsigned long);
+#if defined(BOOST_HAS_LONG_LONG)
+ std::size_t hash_value(long long);
+ std::size_t hash_value(unsigned long long);
+#endif
+
#if !BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x847))
template <class T> std::size_t hash_value(T* const&);
#else
@@ -79,8 +88,55 @@
template <class K, class T, class C, class A>
std::size_t hash_value(std::multimap<K, T, C, A> const& v);
+ template <class T>
+ std::size_t hash_value(std::complex<T> const&);
+
// Implementation
+ namespace hash_detail
+ {
+ template <class T>
+ inline size_t hash_value_signed(T val)
+ {
+ const int size_t_bits = std::numeric_limits<size_t>::digits;
+ // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
+ const int length = (std::numeric_limits<T>::digits - 1)
+ / size_t_bits;
+
+ size_t seed = 0;
+ T positive = val < 0 ? -1 - val : val;
+
+ // Hopefully, this loop can be unrolled.
+ for(unsigned int i = length * size_t_bits; i > 0; i -=
size_t_bits)
+ {
+ seed ^= (size_t) (positive >> i) + (seed<<6) + (seed>>2);
+ }
+ seed ^= (size_t) val + (seed<<6) + (seed>>2);
+
+ return seed;
+ }
+
+ template <class T>
+ inline size_t hash_value_unsigned(T val)
+ {
+ const int size_t_bits = std::numeric_limits<size_t>::digits;
+ // ceiling(std::numeric_limits<T>::digits / size_t_bits) - 1
+ const int length = (std::numeric_limits<T>::digits - 1)
+ / size_t_bits;
+
+ size_t seed = 0;
+
+ // Hopefully, this loop can be unrolled.
+ for(unsigned int i = length * size_t_bits; i > 0; i -=
size_t_bits)
+ {
+ seed ^= (size_t) (val >> i) + (seed<<6) + (seed>>2);
+ }
+ seed ^= (size_t) val + (seed<<6) + (seed>>2);
+
+ return seed;
+ }
+ }
+
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
inline std::size_t hash_value(bool v)
{
@@ -108,6 +164,18 @@
return static_cast<std::size_t>(v);
}
+#if defined(BOOST_HAS_LONG_LONG)
+ inline std::size_t hash_value(long long v)
+ {
+ return hash_detail::hash_value_signed(v);
+ }
+
+ inline std::size_t hash_value(unsigned long long v)
+ {
+ return hash_detail::hash_value_unsigned(v);
+ }
+#endif
+
// Implementation by Alberto Barbati and Dave Harris.
#if !BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x847))
template <class T> std::size_t hash_value(T* const& v)
@@ -266,6 +334,15 @@
return hash_range(v.begin(), v.end());
}
+ template <class K, class T, class C, class A>
+ std::size_t hash_value(std::complex<T> const& v)
+ {
+ boost::hash<T> hasher;
+ std::size_t seed = hasher(v.imag());
+ seed ^= hasher(v.real()) + (seed<<6) + (seed>>2);
+ return seed;
+ }
+
//
// boost::hash
//
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs