Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2007-09-14 06:53:52


Author: danieljames
Date: 2007-09-14 06:53:52 EDT (Fri, 14 Sep 2007)
New Revision: 39263
URL: http://svn.boost.org/trac/boost/changeset/39263

Log:
Use a binary hash function for floats on cygwin as the standard float functions
aren't very good. I should add a check that this really is an x86 based
platform, and perhaps use this sort of hash on other platforms as it can be
more efficient - particularly on Visual C++ which has a slow float to integer
conversion.

Text files modified:
   branches/hash/boost/functional/detail/hash_float.hpp | 30 +++++++++++++++++++++++++++++-
   1 files changed, 29 insertions(+), 1 deletions(-)

Modified: branches/hash/boost/functional/detail/hash_float.hpp
==============================================================================
--- branches/hash/boost/functional/detail/hash_float.hpp (original)
+++ branches/hash/boost/functional/detail/hash_float.hpp 2007-09-14 06:53:52 EDT (Fri, 14 Sep 2007)
@@ -20,7 +20,8 @@
 #include <boost/assert.hpp>
 
 // Don't use fpclassify or _fpclass for stlport.
-#if !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
+// Also don't use it for cygwin as it doesn't support long double.
+#if !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) && !defined(__CYGWIN__)
 # if defined(__GLIBCPP__) || defined(__GLIBCXX__)
 // GNU libstdc++ 3
 # if (defined(__USE_ISOC99) || defined(_GLIBCXX_USE_C99_MATH)) && \
@@ -77,6 +78,33 @@
             seed ^= value + (seed<<6) + (seed>>2);
         }
 
+// On CYGWIN use a simple, utterly non-portable hash algorithm.
+#if defined(__CYGWIN__)
+ inline std::size_t float_hash_impl(float v)
+ {
+ unsigned* ptr = (unsigned*)&v;
+ std::size_t seed = *ptr;
+ return seed;
+ }
+
+ inline std::size_t float_hash_impl(double v)
+ {
+ unsigned* ptr = (unsigned*)&v;
+ std::size_t seed = *ptr++;
+ hash_float_combine(seed, *ptr);
+ return seed;
+ }
+
+ inline std::size_t float_hash_impl(long double v)
+ {
+ unsigned* ptr = (unsigned*)&v;
+ std::size_t seed = *ptr++;
+ hash_float_combine(seed, *ptr++);
+ hash_float_combine(seed, *(unsigned short*)ptr);
+ return seed;
+ }
+#endif
+
         template <class T>
         inline std::size_t float_hash_impl(T v)
         {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk