xref: /freebsd/contrib/llvm-project/libcxx/include/ext/__hash (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_EXT_HASH
110b57cec5SDimitry Andric#define _LIBCPP_EXT_HASH
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric#  pragma GCC system_header
140b57cec5SDimitry Andric
1581ad6265SDimitry Andric#include <__config>
160b57cec5SDimitry Andric#include <cstring>
17*bdd1243dSDimitry Andric#include <stddef.h>
1804eeddc0SDimitry Andric#include <string>
190b57cec5SDimitry Andric
200b57cec5SDimitry Andricnamespace __gnu_cxx {
210b57cec5SDimitry Andric
220b57cec5SDimitry Andrictemplate <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { };
230b57cec5SDimitry Andric
240b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<const char*>
2581ad6265SDimitry Andric : public std::__unary_function<const char*, size_t>
260b57cec5SDimitry Andric{
270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
280b57cec5SDimitry Andric    size_t operator()(const char *__c) const _NOEXCEPT
290b57cec5SDimitry Andric    {
300b57cec5SDimitry Andric        return std::__do_string_hash(__c, __c + strlen(__c));
310b57cec5SDimitry Andric    }
320b57cec5SDimitry Andric};
330b57cec5SDimitry Andric
340b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<char *>
3581ad6265SDimitry Andric : public std::__unary_function<char*, size_t>
360b57cec5SDimitry Andric{
370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
380b57cec5SDimitry Andric    size_t operator()(char *__c) const _NOEXCEPT
390b57cec5SDimitry Andric    {
400b57cec5SDimitry Andric        return std::__do_string_hash<const char *>(__c, __c + strlen(__c));
410b57cec5SDimitry Andric    }
420b57cec5SDimitry Andric};
430b57cec5SDimitry Andric
440b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<char>
4581ad6265SDimitry Andric : public std::__unary_function<char, size_t>
460b57cec5SDimitry Andric{
470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
480b57cec5SDimitry Andric    size_t operator()(char __c) const _NOEXCEPT
490b57cec5SDimitry Andric    {
500b57cec5SDimitry Andric        return __c;
510b57cec5SDimitry Andric    }
520b57cec5SDimitry Andric};
530b57cec5SDimitry Andric
540b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<signed char>
5581ad6265SDimitry Andric : public std::__unary_function<signed char, size_t>
560b57cec5SDimitry Andric{
570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
580b57cec5SDimitry Andric    size_t operator()(signed char __c) const _NOEXCEPT
590b57cec5SDimitry Andric    {
600b57cec5SDimitry Andric        return __c;
610b57cec5SDimitry Andric    }
620b57cec5SDimitry Andric};
630b57cec5SDimitry Andric
640b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
6581ad6265SDimitry Andric : public std::__unary_function<unsigned char, size_t>
660b57cec5SDimitry Andric{
670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
680b57cec5SDimitry Andric    size_t operator()(unsigned char __c) const _NOEXCEPT
690b57cec5SDimitry Andric    {
700b57cec5SDimitry Andric        return __c;
710b57cec5SDimitry Andric    }
720b57cec5SDimitry Andric};
730b57cec5SDimitry Andric
740b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<short>
7581ad6265SDimitry Andric : public std::__unary_function<short, size_t>
760b57cec5SDimitry Andric{
770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
780b57cec5SDimitry Andric    size_t operator()(short __c) const _NOEXCEPT
790b57cec5SDimitry Andric    {
800b57cec5SDimitry Andric        return __c;
810b57cec5SDimitry Andric    }
820b57cec5SDimitry Andric};
830b57cec5SDimitry Andric
840b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
8581ad6265SDimitry Andric : public std::__unary_function<unsigned short, size_t>
860b57cec5SDimitry Andric{
870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
880b57cec5SDimitry Andric    size_t operator()(unsigned short __c) const _NOEXCEPT
890b57cec5SDimitry Andric    {
900b57cec5SDimitry Andric        return __c;
910b57cec5SDimitry Andric    }
920b57cec5SDimitry Andric};
930b57cec5SDimitry Andric
940b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<int>
9581ad6265SDimitry Andric    : public std::__unary_function<int, size_t>
960b57cec5SDimitry Andric{
970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
980b57cec5SDimitry Andric    size_t operator()(int __c) const _NOEXCEPT
990b57cec5SDimitry Andric    {
1000b57cec5SDimitry Andric        return __c;
1010b57cec5SDimitry Andric    }
1020b57cec5SDimitry Andric};
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
10581ad6265SDimitry Andric    : public std::__unary_function<unsigned int, size_t>
1060b57cec5SDimitry Andric{
1070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1080b57cec5SDimitry Andric    size_t operator()(unsigned int __c) const _NOEXCEPT
1090b57cec5SDimitry Andric    {
1100b57cec5SDimitry Andric        return __c;
1110b57cec5SDimitry Andric    }
1120b57cec5SDimitry Andric};
1130b57cec5SDimitry Andric
1140b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<long>
11581ad6265SDimitry Andric    : public std::__unary_function<long, size_t>
1160b57cec5SDimitry Andric{
1170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1180b57cec5SDimitry Andric    size_t operator()(long __c) const _NOEXCEPT
1190b57cec5SDimitry Andric    {
1200b57cec5SDimitry Andric        return __c;
1210b57cec5SDimitry Andric    }
1220b57cec5SDimitry Andric};
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andrictemplate <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
12581ad6265SDimitry Andric    : public std::__unary_function<unsigned long, size_t>
1260b57cec5SDimitry Andric{
1270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1280b57cec5SDimitry Andric    size_t operator()(unsigned long __c) const _NOEXCEPT
1290b57cec5SDimitry Andric    {
1300b57cec5SDimitry Andric        return __c;
1310b57cec5SDimitry Andric    }
1320b57cec5SDimitry Andric};
1330eae32dcSDimitry Andric} // namespace __gnu_cxx
1340b57cec5SDimitry Andric
1350b57cec5SDimitry Andric#endif // _LIBCPP_EXT_HASH
136