__hash 3.2 KB

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