Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

hash_fun.h 4.1KB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // 'struct hash' from SGI -*- C++ -*-
  2. // Copyright (C) 2001-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /*
  21. * Copyright (c) 1996-1998
  22. * Silicon Graphics Computer Systems, Inc.
  23. *
  24. * Permission to use, copy, modify, distribute and sell this software
  25. * and its documentation for any purpose is hereby granted without fee,
  26. * provided that the above copyright notice appear in all copies and
  27. * that both that copyright notice and this permission notice appear
  28. * in supporting documentation. Silicon Graphics makes no
  29. * representations about the suitability of this software for any
  30. * purpose. It is provided "as is" without express or implied warranty.
  31. *
  32. *
  33. * Copyright (c) 1994
  34. * Hewlett-Packard Company
  35. *
  36. * Permission to use, copy, modify, distribute and sell this software
  37. * and its documentation for any purpose is hereby granted without fee,
  38. * provided that the above copyright notice appear in all copies and
  39. * that both that copyright notice and this permission notice appear
  40. * in supporting documentation. Hewlett-Packard Company makes no
  41. * representations about the suitability of this software for any
  42. * purpose. It is provided "as is" without express or implied warranty.
  43. *
  44. */
  45. /** @file backward/hash_fun.h
  46. * This file is a GNU extension to the Standard C++ Library (possibly
  47. * containing extensions from the HP/SGI STL subset).
  48. */
  49. #ifndef _BACKWARD_HASH_FUN_H
  50. #define _BACKWARD_HASH_FUN_H 1
  51. #include <bits/c++config.h>
  52. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  53. {
  54. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  55. using std::size_t;
  56. template<class _Key>
  57. struct hash { };
  58. inline size_t
  59. __stl_hash_string(const char* __s)
  60. {
  61. unsigned long __h = 0;
  62. for ( ; *__s; ++__s)
  63. __h = 5 * __h + *__s;
  64. return size_t(__h);
  65. }
  66. template<>
  67. struct hash<char*>
  68. {
  69. size_t
  70. operator()(const char* __s) const
  71. { return __stl_hash_string(__s); }
  72. };
  73. template<>
  74. struct hash<const char*>
  75. {
  76. size_t
  77. operator()(const char* __s) const
  78. { return __stl_hash_string(__s); }
  79. };
  80. template<>
  81. struct hash<char>
  82. {
  83. size_t
  84. operator()(char __x) const
  85. { return __x; }
  86. };
  87. template<>
  88. struct hash<unsigned char>
  89. {
  90. size_t
  91. operator()(unsigned char __x) const
  92. { return __x; }
  93. };
  94. template<>
  95. struct hash<signed char>
  96. {
  97. size_t
  98. operator()(unsigned char __x) const
  99. { return __x; }
  100. };
  101. template<>
  102. struct hash<short>
  103. {
  104. size_t
  105. operator()(short __x) const
  106. { return __x; }
  107. };
  108. template<>
  109. struct hash<unsigned short>
  110. {
  111. size_t
  112. operator()(unsigned short __x) const
  113. { return __x; }
  114. };
  115. template<>
  116. struct hash<int>
  117. {
  118. size_t
  119. operator()(int __x) const
  120. { return __x; }
  121. };
  122. template<>
  123. struct hash<unsigned int>
  124. {
  125. size_t
  126. operator()(unsigned int __x) const
  127. { return __x; }
  128. };
  129. template<>
  130. struct hash<long>
  131. {
  132. size_t
  133. operator()(long __x) const
  134. { return __x; }
  135. };
  136. template<>
  137. struct hash<unsigned long>
  138. {
  139. size_t
  140. operator()(unsigned long __x) const
  141. { return __x; }
  142. };
  143. _GLIBCXX_END_NAMESPACE_VERSION
  144. } // namespace
  145. #endif