/indra/llcommon/llhash.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 72 lines · 36 code · 7 blank · 29 comment · 6 complexity · 58e585ddf0e16f2b0bb89ef560aeaa7c MD5 · raw file

  1. /**
  2. * @file llhash.h
  3. * @brief Wrapper for a hash function.
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLHASH_H
  27. #define LL_LLHASH_H
  28. #include "llpreprocessor.h" // for GCC_VERSION
  29. #if (LL_WINDOWS)
  30. #include <hash_map>
  31. #include <algorithm>
  32. #elif LL_DARWIN || LL_LINUX
  33. # if GCC_VERSION >= 40300 // gcc 4.3 and up
  34. # include <backward/hashtable.h>
  35. # elif GCC_VERSION >= 30400 // gcc 3.4 and up
  36. # include <ext/hashtable.h>
  37. # elif __GNUC__ >= 3
  38. # include <ext/stl_hashtable.h>
  39. # else
  40. # include <hashtable.h>
  41. # endif
  42. #elif LL_SOLARIS
  43. #include <ext/hashtable.h>
  44. #else
  45. #error Please define your platform.
  46. #endif
  47. // Warning - an earlier template-based version of this routine did not do
  48. // the correct thing on Windows. Since this is only used to get
  49. // a string hash, it was converted to a regular routine and
  50. // unit tests added.
  51. inline size_t llhash( const char * value )
  52. {
  53. #if LL_WINDOWS
  54. return stdext::hash_value(value);
  55. #elif ( (defined _STLPORT_VERSION) || ((LL_LINUX) && (__GNUC__ <= 2)) )
  56. std::hash<const char *> H;
  57. return H(value);
  58. #elif LL_DARWIN || LL_LINUX || LL_SOLARIS
  59. __gnu_cxx::hash<const char *> H;
  60. return H(value);
  61. #else
  62. #error Please define your platform.
  63. #endif
  64. }
  65. #endif