xref: /freebsd-12.1/contrib/libc++/include/ext/__hash (revision aed8d94e)
17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===------------------------- hash_set ------------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_EXT_HASH
127a984708SDavid Chisnall#define _LIBCPP_EXT_HASH
137a984708SDavid Chisnall
147a984708SDavid Chisnall#pragma GCC system_header
157a984708SDavid Chisnall
167a984708SDavid Chisnall#include <string>
177a984708SDavid Chisnall#include <cstring>
187a984708SDavid Chisnall
197a984708SDavid Chisnallnamespace __gnu_cxx {
207a984708SDavid Chisnallusing namespace std;
217a984708SDavid Chisnall
22*aed8d94eSDimitry Andrictemplate <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { };
237a984708SDavid Chisnall
24*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<const char*>
257a984708SDavid Chisnall    : public unary_function<const char*, size_t>
267a984708SDavid Chisnall{
277a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
287a984708SDavid Chisnall    size_t operator()(const char *__c) const _NOEXCEPT
297a984708SDavid Chisnall    {
307a984708SDavid Chisnall        return __do_string_hash(__c, __c + strlen(__c));
317a984708SDavid Chisnall    }
327a984708SDavid Chisnall};
337a984708SDavid Chisnall
34*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<char *>
357a984708SDavid Chisnall    : public unary_function<char*, size_t>
367a984708SDavid Chisnall{
377a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
387a984708SDavid Chisnall    size_t operator()(char *__c) const _NOEXCEPT
397a984708SDavid Chisnall    {
407a984708SDavid Chisnall        return __do_string_hash<const char *>(__c, __c + strlen(__c));
417a984708SDavid Chisnall    }
427a984708SDavid Chisnall};
43d72607e9SDimitry Andric
44*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<char>
45d72607e9SDimitry Andric    : public unary_function<char, size_t>
46d72607e9SDimitry Andric{
47d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
48d72607e9SDimitry Andric    size_t operator()(char __c) const _NOEXCEPT
49d72607e9SDimitry Andric    {
50d72607e9SDimitry Andric        return __c;
51d72607e9SDimitry Andric    }
52d72607e9SDimitry Andric};
53d72607e9SDimitry Andric
54*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<signed char>
55d72607e9SDimitry Andric    : public unary_function<signed char, size_t>
56d72607e9SDimitry Andric{
57d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
58d72607e9SDimitry Andric    size_t operator()(signed char __c) const _NOEXCEPT
59d72607e9SDimitry Andric    {
60d72607e9SDimitry Andric        return __c;
61d72607e9SDimitry Andric    }
62d72607e9SDimitry Andric};
63d72607e9SDimitry Andric
64*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
65d72607e9SDimitry Andric    : public unary_function<unsigned char, size_t>
66d72607e9SDimitry Andric{
67d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
68d72607e9SDimitry Andric    size_t operator()(unsigned char __c) const _NOEXCEPT
69d72607e9SDimitry Andric    {
70d72607e9SDimitry Andric        return __c;
71d72607e9SDimitry Andric    }
72d72607e9SDimitry Andric};
73d72607e9SDimitry Andric
74*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<short>
75d72607e9SDimitry Andric    : public unary_function<short, size_t>
76d72607e9SDimitry Andric{
77d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
78d72607e9SDimitry Andric    size_t operator()(short __c) const _NOEXCEPT
79d72607e9SDimitry Andric    {
80d72607e9SDimitry Andric        return __c;
81d72607e9SDimitry Andric    }
82d72607e9SDimitry Andric};
83d72607e9SDimitry Andric
84*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
85d72607e9SDimitry Andric    : public unary_function<unsigned short, size_t>
86d72607e9SDimitry Andric{
87d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
88d72607e9SDimitry Andric    size_t operator()(unsigned short __c) const _NOEXCEPT
89d72607e9SDimitry Andric    {
90d72607e9SDimitry Andric        return __c;
91d72607e9SDimitry Andric    }
92d72607e9SDimitry Andric};
93d72607e9SDimitry Andric
94*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<int>
95d72607e9SDimitry Andric    : public unary_function<int, size_t>
96d72607e9SDimitry Andric{
97d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
98d72607e9SDimitry Andric    size_t operator()(int __c) const _NOEXCEPT
99d72607e9SDimitry Andric    {
100d72607e9SDimitry Andric        return __c;
101d72607e9SDimitry Andric    }
102d72607e9SDimitry Andric};
103d72607e9SDimitry Andric
104*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
105d72607e9SDimitry Andric    : public unary_function<unsigned int, size_t>
106d72607e9SDimitry Andric{
107d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
108d72607e9SDimitry Andric    size_t operator()(unsigned int __c) const _NOEXCEPT
109d72607e9SDimitry Andric    {
110d72607e9SDimitry Andric        return __c;
111d72607e9SDimitry Andric    }
112d72607e9SDimitry Andric};
113d72607e9SDimitry Andric
114*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<long>
115d72607e9SDimitry Andric    : public unary_function<long, size_t>
116d72607e9SDimitry Andric{
117d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
118d72607e9SDimitry Andric    size_t operator()(long __c) const _NOEXCEPT
119d72607e9SDimitry Andric    {
120d72607e9SDimitry Andric        return __c;
121d72607e9SDimitry Andric    }
122d72607e9SDimitry Andric};
123d72607e9SDimitry Andric
124*aed8d94eSDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
125d72607e9SDimitry Andric    : public unary_function<unsigned long, size_t>
126d72607e9SDimitry Andric{
127d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
128d72607e9SDimitry Andric    size_t operator()(unsigned long __c) const _NOEXCEPT
129d72607e9SDimitry Andric    {
130d72607e9SDimitry Andric        return __c;
131d72607e9SDimitry Andric    }
132d72607e9SDimitry Andric};
1337a984708SDavid Chisnall}
1347a984708SDavid Chisnall
1351e0896acSDavid Chisnall#endif  // _LIBCPP_EXT_HASH
136