hash_fun.hxx.in 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. /*
  11. * Copyright (c) 1996
  12. * Silicon Graphics Computer Systems, Inc.
  13. *
  14. * Permission to use, copy, modify, distribute and sell this software
  15. * and its documentation for any purpose is hereby granted without fee,
  16. * provided that the above copyright notice appear in all copies and
  17. * that both that copyright notice and this permission notice appear
  18. * in supporting documentation. Silicon Graphics makes no
  19. * representations about the suitability of this software for any
  20. * purpose. It is provided "as is" without express or implied warranty.
  21. *
  22. *
  23. * Copyright (c) 1994
  24. * Hewlett-Packard Company
  25. *
  26. * Permission to use, copy, modify, distribute and sell this software
  27. * and its documentation for any purpose is hereby granted without fee,
  28. * provided that the above copyright notice appear in all copies and
  29. * that both that copyright notice and this permission notice appear
  30. * in supporting documentation. Hewlett-Packard Company makes no
  31. * representations about the suitability of this software for any
  32. * purpose. It is provided "as is" without express or implied warranty.
  33. *
  34. */
  35. #ifndef @KWSYS_NAMESPACE@_hash_fun_hxx
  36. #define @KWSYS_NAMESPACE@_hash_fun_hxx
  37. #include <@KWSYS_NAMESPACE@/Configure.hxx>
  38. #include <stddef.h> // size_t
  39. #include <string>
  40. namespace @KWSYS_NAMESPACE@
  41. {
  42. template <class _Key> struct hash { };
  43. inline size_t _stl_hash_string(const char* __s)
  44. {
  45. unsigned long __h = 0;
  46. for ( ; *__s; ++__s)
  47. __h = 5*__h + *__s;
  48. return size_t(__h);
  49. }
  50. template <>
  51. struct hash<char*> {
  52. size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
  53. };
  54. template <>
  55. struct hash<const char*> {
  56. size_t operator()(const char* __s) const { return _stl_hash_string(__s); }
  57. };
  58. template <>
  59. struct hash<std::string> {
  60. size_t operator()(const std::string & __s) const { return _stl_hash_string(__s.c_str()); }
  61. };
  62. #if !defined(__BORLANDC__)
  63. template <>
  64. struct hash<const std::string> {
  65. size_t operator()(const std::string & __s) const { return _stl_hash_string(__s.c_str()); }
  66. };
  67. #endif
  68. template <>
  69. struct hash<char> {
  70. size_t operator()(char __x) const { return __x; }
  71. };
  72. template <>
  73. struct hash<unsigned char> {
  74. size_t operator()(unsigned char __x) const { return __x; }
  75. };
  76. template <>
  77. struct hash<signed char> {
  78. size_t operator()(unsigned char __x) const { return __x; }
  79. };
  80. template <>
  81. struct hash<short> {
  82. size_t operator()(short __x) const { return __x; }
  83. };
  84. template <>
  85. struct hash<unsigned short> {
  86. size_t operator()(unsigned short __x) const { return __x; }
  87. };
  88. template <>
  89. struct hash<int> {
  90. size_t operator()(int __x) const { return __x; }
  91. };
  92. template <>
  93. struct hash<unsigned int> {
  94. size_t operator()(unsigned int __x) const { return __x; }
  95. };
  96. template <>
  97. struct hash<long> {
  98. size_t operator()(long __x) const { return __x; }
  99. };
  100. template <>
  101. struct hash<unsigned long> {
  102. size_t operator()(unsigned long __x) const { return __x; }
  103. };
  104. // use long long or __int64
  105. #if @KWSYS_USE_LONG_LONG@
  106. template <>
  107. struct hash<long long> {
  108. size_t operator()(long long __x) const { return __x; }
  109. };
  110. template <>
  111. struct hash<unsigned long long> {
  112. size_t operator()(unsigned long long __x) const { return __x; }
  113. };
  114. #elif @KWSYS_USE___INT64@
  115. template <>
  116. struct hash<__int64> {
  117. size_t operator()(__int64 __x) const { return __x; }
  118. };
  119. template <>
  120. struct hash<unsigned __int64> {
  121. size_t operator()(unsigned __int64 __x) const { return __x; }
  122. };
  123. #endif // use long long or __int64
  124. } // namespace @KWSYS_NAMESPACE@
  125. #endif