hash_fun.hxx.in 3.6 KB

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