xref: /reactos/sdk/include/c++/stlport/stl/_hash_fun.h (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Copyright (c) 1996-1998
3*c2c66affSColin Finck  * Silicon Graphics Computer Systems, Inc.
4*c2c66affSColin Finck  *
5*c2c66affSColin Finck  * Permission to use, copy, modify, distribute and sell this software
6*c2c66affSColin Finck  * and its documentation for any purpose is hereby granted without fee,
7*c2c66affSColin Finck  * provided that the above copyright notice appear in all copies and
8*c2c66affSColin Finck  * that both that copyright notice and this permission notice appear
9*c2c66affSColin Finck  * in supporting documentation.  Silicon Graphics makes no
10*c2c66affSColin Finck  * representations about the suitability of this software for any
11*c2c66affSColin Finck  * purpose.  It is provided "as is" without express or implied warranty.
12*c2c66affSColin Finck  *
13*c2c66affSColin Finck  *
14*c2c66affSColin Finck  * Copyright (c) 1994
15*c2c66affSColin Finck  * Hewlett-Packard Company
16*c2c66affSColin Finck  *
17*c2c66affSColin Finck  * Permission to use, copy, modify, distribute and sell this software
18*c2c66affSColin Finck  * and its documentation for any purpose is hereby granted without fee,
19*c2c66affSColin Finck  * provided that the above copyright notice appear in all copies and
20*c2c66affSColin Finck  * that both that copyright notice and this permission notice appear
21*c2c66affSColin Finck  * in supporting documentation.  Hewlett-Packard Company makes no
22*c2c66affSColin Finck  * representations about the suitability of this software for any
23*c2c66affSColin Finck  * purpose.  It is provided "as is" without express or implied warranty.
24*c2c66affSColin Finck  *
25*c2c66affSColin Finck  */
26*c2c66affSColin Finck 
27*c2c66affSColin Finck /* NOTE: This is an internal header file, included by other STL headers.
28*c2c66affSColin Finck  *   You should not attempt to use it directly.
29*c2c66affSColin Finck  */
30*c2c66affSColin Finck 
31*c2c66affSColin Finck #ifndef _STLP_HASH_FUN_H
32*c2c66affSColin Finck #define _STLP_HASH_FUN_H
33*c2c66affSColin Finck 
34*c2c66affSColin Finck #ifndef _STLP_INTERNAL_CSTDDEF
35*c2c66affSColin Finck #  include <stl/_cstddef.h>
36*c2c66affSColin Finck #endif
37*c2c66affSColin Finck 
38*c2c66affSColin Finck _STLP_BEGIN_NAMESPACE
39*c2c66affSColin Finck 
40*c2c66affSColin Finck template <class _Key> struct hash { };
41*c2c66affSColin Finck 
42*c2c66affSColin Finck _STLP_MOVE_TO_PRIV_NAMESPACE
43*c2c66affSColin Finck 
__stl_hash_string(const char * __s)44*c2c66affSColin Finck inline size_t __stl_hash_string(const char* __s) {
45*c2c66affSColin Finck   _STLP_FIX_LITERAL_BUG(__s)
46*c2c66affSColin Finck   unsigned long __h = 0;
47*c2c66affSColin Finck   for ( ; *__s; ++__s)
48*c2c66affSColin Finck     __h = 5*__h + *__s;
49*c2c66affSColin Finck 
50*c2c66affSColin Finck   return size_t(__h);
51*c2c66affSColin Finck }
52*c2c66affSColin Finck 
53*c2c66affSColin Finck _STLP_MOVE_TO_STD_NAMESPACE
54*c2c66affSColin Finck 
55*c2c66affSColin Finck _STLP_TEMPLATE_NULL
56*c2c66affSColin Finck struct hash<char*> {
57*c2c66affSColin Finck   size_t operator()(const char* __s) const {
58*c2c66affSColin Finck     _STLP_FIX_LITERAL_BUG(__s)
59*c2c66affSColin Finck     return _STLP_PRIV __stl_hash_string(__s);
60*c2c66affSColin Finck   }
61*c2c66affSColin Finck };
62*c2c66affSColin Finck 
63*c2c66affSColin Finck _STLP_TEMPLATE_NULL
64*c2c66affSColin Finck struct hash<const char*> {
65*c2c66affSColin Finck   size_t operator()(const char* __s) const {
66*c2c66affSColin Finck     _STLP_FIX_LITERAL_BUG(__s)
67*c2c66affSColin Finck     return _STLP_PRIV __stl_hash_string(__s);
68*c2c66affSColin Finck   }
69*c2c66affSColin Finck };
70*c2c66affSColin Finck 
71*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<char> {
72*c2c66affSColin Finck   size_t operator()(char __x) const { return __x; }
73*c2c66affSColin Finck };
74*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<unsigned char> {
75*c2c66affSColin Finck   size_t operator()(unsigned char __x) const { return __x; }
76*c2c66affSColin Finck };
77*c2c66affSColin Finck #if !defined (_STLP_NO_SIGNED_BUILTINS)
78*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<signed char> {
79*c2c66affSColin Finck   size_t operator()(unsigned char __x) const { return __x; }
80*c2c66affSColin Finck };
81*c2c66affSColin Finck #endif
82*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<short> {
83*c2c66affSColin Finck   size_t operator()(short __x) const { return __x; }
84*c2c66affSColin Finck };
85*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<unsigned short> {
86*c2c66affSColin Finck   size_t operator()(unsigned short __x) const { return __x; }
87*c2c66affSColin Finck };
88*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<int> {
89*c2c66affSColin Finck   size_t operator()(int __x) const { return __x; }
90*c2c66affSColin Finck };
91*c2c66affSColin Finck 
92*c2c66affSColin Finck #if !defined (_STLP_MSVC) || (_STLP_MSVC < 1300) || defined (_WIN64)
93*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<unsigned int> {
94*c2c66affSColin Finck   size_t operator()(unsigned int __x) const { return __x; }
95*c2c66affSColin Finck };
96*c2c66affSColin Finck #else
97*c2c66affSColin Finck /* MSVC .Net since 2002 has a 64 bits portability warning feature. typedef
98*c2c66affSColin Finck  * like size_t are tagged as potential 64 bits variables making them different from
99*c2c66affSColin Finck  * unsigned int. To avoid the warning when a hash container is instanciated with
100*c2c66affSColin Finck  * the size_t key we prefer to grant the size_t specialization rather than the
101*c2c66affSColin Finck  * unsigned int one.
102*c2c66affSColin Finck  */
103*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<size_t> {
104*c2c66affSColin Finck   size_t operator()(size_t __x) const { return __x; }
105*c2c66affSColin Finck };
106*c2c66affSColin Finck #endif
107*c2c66affSColin Finck 
108*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<long> {
109*c2c66affSColin Finck   size_t operator()(long __x) const { return __x; }
110*c2c66affSColin Finck };
111*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<unsigned long> {
112*c2c66affSColin Finck   size_t operator()(unsigned long __x) const { return __x; }
113*c2c66affSColin Finck };
114*c2c66affSColin Finck 
115*c2c66affSColin Finck #if defined (_STLP_LONG_LONG)
116*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<_STLP_LONG_LONG> {
117*c2c66affSColin Finck   size_t operator()(_STLP_LONG_LONG x) const { return (size_t)x; }
118*c2c66affSColin Finck };
119*c2c66affSColin Finck _STLP_TEMPLATE_NULL struct hash<unsigned _STLP_LONG_LONG> {
120*c2c66affSColin Finck   size_t operator()(unsigned _STLP_LONG_LONG x) const { return (size_t)x; }
121*c2c66affSColin Finck };
122*c2c66affSColin Finck #endif
123*c2c66affSColin Finck 
124*c2c66affSColin Finck _STLP_TEMPLATE_NULL
125*c2c66affSColin Finck struct hash<void *>
126*c2c66affSColin Finck {
127*c2c66affSColin Finck     union __vp {
128*c2c66affSColin Finck         size_t s;
129*c2c66affSColin Finck         void  *p;
130*c2c66affSColin Finck     };
131*c2c66affSColin Finck 
132*c2c66affSColin Finck     size_t operator()(void *__x) const
133*c2c66affSColin Finck       {
134*c2c66affSColin Finck         __vp vp;
135*c2c66affSColin Finck         vp.p = __x;
136*c2c66affSColin Finck         return vp.s;
137*c2c66affSColin Finck       }
138*c2c66affSColin Finck };
139*c2c66affSColin Finck 
140*c2c66affSColin Finck _STLP_END_NAMESPACE
141*c2c66affSColin Finck 
142*c2c66affSColin Finck #endif /* _STLP_HASH_FUN_H */
143*c2c66affSColin Finck 
144*c2c66affSColin Finck // Local Variables:
145*c2c66affSColin Finck // mode:C++
146*c2c66affSColin Finck // End:
147