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