__hash 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // -*- C++ -*-
  2. //===------------------------- hash_set ------------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_EXT_HASH
  11. #define _LIBCPP_EXT_HASH
  12. #pragma GCC system_header
  13. #include <string>
  14. #include <cstring>
  15. namespace __gnu_cxx {
  16. using namespace std;
  17. template <typename _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash { };
  18. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<const char*>
  19. : public unary_function<const char*, size_t>
  20. {
  21. _LIBCPP_INLINE_VISIBILITY
  22. size_t operator()(const char *__c) const _NOEXCEPT
  23. {
  24. return __do_string_hash(__c, __c + strlen(__c));
  25. }
  26. };
  27. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char *>
  28. : public unary_function<char*, size_t>
  29. {
  30. _LIBCPP_INLINE_VISIBILITY
  31. size_t operator()(char *__c) const _NOEXCEPT
  32. {
  33. return __do_string_hash<const char *>(__c, __c + strlen(__c));
  34. }
  35. };
  36. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<char>
  37. : public unary_function<char, size_t>
  38. {
  39. _LIBCPP_INLINE_VISIBILITY
  40. size_t operator()(char __c) const _NOEXCEPT
  41. {
  42. return __c;
  43. }
  44. };
  45. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
  46. : public unary_function<signed char, size_t>
  47. {
  48. _LIBCPP_INLINE_VISIBILITY
  49. size_t operator()(signed char __c) const _NOEXCEPT
  50. {
  51. return __c;
  52. }
  53. };
  54. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
  55. : public unary_function<unsigned char, size_t>
  56. {
  57. _LIBCPP_INLINE_VISIBILITY
  58. size_t operator()(unsigned char __c) const _NOEXCEPT
  59. {
  60. return __c;
  61. }
  62. };
  63. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<short>
  64. : public unary_function<short, size_t>
  65. {
  66. _LIBCPP_INLINE_VISIBILITY
  67. size_t operator()(short __c) const _NOEXCEPT
  68. {
  69. return __c;
  70. }
  71. };
  72. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
  73. : public unary_function<unsigned short, size_t>
  74. {
  75. _LIBCPP_INLINE_VISIBILITY
  76. size_t operator()(unsigned short __c) const _NOEXCEPT
  77. {
  78. return __c;
  79. }
  80. };
  81. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<int>
  82. : public unary_function<int, size_t>
  83. {
  84. _LIBCPP_INLINE_VISIBILITY
  85. size_t operator()(int __c) const _NOEXCEPT
  86. {
  87. return __c;
  88. }
  89. };
  90. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
  91. : public unary_function<unsigned int, size_t>
  92. {
  93. _LIBCPP_INLINE_VISIBILITY
  94. size_t operator()(unsigned int __c) const _NOEXCEPT
  95. {
  96. return __c;
  97. }
  98. };
  99. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<long>
  100. : public unary_function<long, size_t>
  101. {
  102. _LIBCPP_INLINE_VISIBILITY
  103. size_t operator()(long __c) const _NOEXCEPT
  104. {
  105. return __c;
  106. }
  107. };
  108. template <> struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
  109. : public unary_function<unsigned long, size_t>
  110. {
  111. _LIBCPP_INLINE_VISIBILITY
  112. size_t operator()(unsigned long __c) const _NOEXCEPT
  113. {
  114. return __c;
  115. }
  116. };
  117. }
  118. #endif // _LIBCPP_EXT_HASH