Skip to content
Snippets Groups Projects
Commit 01406501 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

Convert llhash() to use boost::hash, per Cinder's suggestion.

parent ce166675
No related branches found
No related tags found
No related merge requests found
...@@ -27,26 +27,7 @@ ...@@ -27,26 +27,7 @@
#ifndef LL_LLHASH_H #ifndef LL_LLHASH_H
#define LL_LLHASH_H #define LL_LLHASH_H
#include "llpreprocessor.h" // for GCC_VERSION #include <boost/functional/hash.hpp>
#if (LL_WINDOWS)
#include <hash_map>
#include <algorithm>
#elif LL_DARWIN || LL_LINUX
# if GCC_VERSION >= 40300 // gcc 4.3 and up
# include <backward/hashtable.h>
# elif GCC_VERSION >= 30400 // gcc 3.4 and up
# include <ext/hashtable.h>
# elif __GNUC__ >= 3
# include <ext/stl_hashtable.h>
# else
# include <hashtable.h>
# endif
#elif LL_SOLARIS
#include <ext/hashtable.h>
#else
#error Please define your platform.
#endif
// Warning - an earlier template-based version of this routine did not do // Warning - an earlier template-based version of this routine did not do
// the correct thing on Windows. Since this is only used to get // the correct thing on Windows. Since this is only used to get
...@@ -55,17 +36,17 @@ ...@@ -55,17 +36,17 @@
inline size_t llhash( const char * value ) inline size_t llhash( const char * value )
{ {
#if LL_WINDOWS // boost::hash is defined for std::string and for char, but there's no
return stdext::hash_value(value); // special overload for const char*. The lazy approach would be to
#elif ( (defined _STLPORT_VERSION) || ((LL_LINUX) && (__GNUC__ <= 2)) ) // instantiate a std::string and take its hash, but that might be more
std::hash<const char *> H; // overhead than our callers want. Or we could use boost::hash_range() --
return H(value); // but that would require a preliminary pass over the value to determine
#elif LL_DARWIN || LL_LINUX || LL_SOLARIS // the end iterator. Instead, use boost::hash_combine() to hash individual
__gnu_cxx::hash<const char *> H; // characters.
return H(value); std::size_t seed = 0;
#else for ( ; *value; ++value)
#error Please define your platform. boost::hash_combine(seed, *value);
#endif return seed;
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment