1// -*- C++ -*- 2//===------------------------- hash_set ------------------------------------===// 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 10#ifndef _LIBCPP_EXT_HASH 11#define _LIBCPP_EXT_HASH 12 13#pragma GCC system_header 14 15#include <string> 16#include <cstring> 17 18namespace __gnu_cxx { 19 20template <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { }; 21 22template <> struct _LIBCPP_TEMPLATE_VIS hash<const char*> 23 : public std::unary_function<const char*, size_t> 24{ 25 _LIBCPP_INLINE_VISIBILITY 26 size_t operator()(const char *__c) const _NOEXCEPT 27 { 28 return std::__do_string_hash(__c, __c + strlen(__c)); 29 } 30}; 31 32template <> struct _LIBCPP_TEMPLATE_VIS hash<char *> 33 : public std::unary_function<char*, size_t> 34{ 35 _LIBCPP_INLINE_VISIBILITY 36 size_t operator()(char *__c) const _NOEXCEPT 37 { 38 return std::__do_string_hash<const char *>(__c, __c + strlen(__c)); 39 } 40}; 41 42template <> struct _LIBCPP_TEMPLATE_VIS hash<char> 43 : public std::unary_function<char, size_t> 44{ 45 _LIBCPP_INLINE_VISIBILITY 46 size_t operator()(char __c) const _NOEXCEPT 47 { 48 return __c; 49 } 50}; 51 52template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char> 53 : public std::unary_function<signed char, size_t> 54{ 55 _LIBCPP_INLINE_VISIBILITY 56 size_t operator()(signed char __c) const _NOEXCEPT 57 { 58 return __c; 59 } 60}; 61 62template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> 63 : public std::unary_function<unsigned char, size_t> 64{ 65 _LIBCPP_INLINE_VISIBILITY 66 size_t operator()(unsigned char __c) const _NOEXCEPT 67 { 68 return __c; 69 } 70}; 71 72template <> struct _LIBCPP_TEMPLATE_VIS hash<short> 73 : public std::unary_function<short, size_t> 74{ 75 _LIBCPP_INLINE_VISIBILITY 76 size_t operator()(short __c) const _NOEXCEPT 77 { 78 return __c; 79 } 80}; 81 82template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> 83 : public std::unary_function<unsigned short, size_t> 84{ 85 _LIBCPP_INLINE_VISIBILITY 86 size_t operator()(unsigned short __c) const _NOEXCEPT 87 { 88 return __c; 89 } 90}; 91 92template <> struct _LIBCPP_TEMPLATE_VIS hash<int> 93 : public std::unary_function<int, size_t> 94{ 95 _LIBCPP_INLINE_VISIBILITY 96 size_t operator()(int __c) const _NOEXCEPT 97 { 98 return __c; 99 } 100}; 101 102template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> 103 : public std::unary_function<unsigned int, size_t> 104{ 105 _LIBCPP_INLINE_VISIBILITY 106 size_t operator()(unsigned int __c) const _NOEXCEPT 107 { 108 return __c; 109 } 110}; 111 112template <> struct _LIBCPP_TEMPLATE_VIS hash<long> 113 : public std::unary_function<long, size_t> 114{ 115 _LIBCPP_INLINE_VISIBILITY 116 size_t operator()(long __c) const _NOEXCEPT 117 { 118 return __c; 119 } 120}; 121 122template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> 123 : public std::unary_function<unsigned long, size_t> 124{ 125 _LIBCPP_INLINE_VISIBILITY 126 size_t operator()(unsigned long __c) const _NOEXCEPT 127 { 128 return __c; 129 } 130}; 131} 132 133#endif // _LIBCPP_EXT_HASH 134