williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 1997-1999
|
williamr@2
|
3 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
4 |
*
|
williamr@4
|
5 |
* Copyright (c) 1999
|
williamr@2
|
6 |
* Boris Fomitchev
|
williamr@2
|
7 |
*
|
williamr@2
|
8 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
9 |
* or implied. Any use is at your own risk.
|
williamr@2
|
10 |
*
|
williamr@4
|
11 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
12 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
13 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
14 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
15 |
* modified is included with the above copyright notice.
|
williamr@2
|
16 |
*
|
williamr@2
|
17 |
*/
|
williamr@2
|
18 |
|
williamr@2
|
19 |
#ifndef _STLP_STRING_HASH_H
|
williamr@4
|
20 |
#define _STLP_STRING_HASH_H
|
williamr@2
|
21 |
|
williamr@2
|
22 |
#ifndef _STLP_HASH_FUN_H
|
williamr@2
|
23 |
# include <stl/_hash_fun.h>
|
williamr@2
|
24 |
#endif
|
williamr@2
|
25 |
|
williamr@4
|
26 |
#ifndef _STLP_INTERNAL_STRING_H
|
williamr@2
|
27 |
# include <stl/_string.h>
|
williamr@2
|
28 |
#endif
|
williamr@2
|
29 |
|
williamr@2
|
30 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
31 |
|
williamr@2
|
32 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
33 |
_STLP_INLINE_LOOP size_t
|
williamr@2
|
34 |
__stl_string_hash(const basic_string<_CharT,_Traits,_Alloc>& __s) {
|
williamr@2
|
35 |
unsigned long __h = 0;
|
williamr@2
|
36 |
size_t __len = __s.size();
|
williamr@2
|
37 |
const _CharT* __data = __s.data();
|
williamr@2
|
38 |
for ( size_t __i = 0; __i < __len; ++__i)
|
williamr@4
|
39 |
__h = /* 5 *__h */(__h << 2) + __h + __data[__i];
|
williamr@2
|
40 |
return size_t(__h);
|
williamr@2
|
41 |
}
|
williamr@2
|
42 |
|
williamr@4
|
43 |
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@2
|
44 |
|
williamr@2
|
45 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
46 |
struct hash<basic_string<_CharT,_Traits,_Alloc> > {
|
williamr@2
|
47 |
size_t operator()(const basic_string<_CharT,_Traits,_Alloc>& __s) const
|
williamr@2
|
48 |
{ return __stl_string_hash(__s); }
|
williamr@2
|
49 |
};
|
williamr@2
|
50 |
|
williamr@2
|
51 |
#else
|
williamr@2
|
52 |
|
williamr@4
|
53 |
_STLP_TEMPLATE_NULL
|
williamr@4
|
54 |
struct _STLP_CLASS_DECLSPEC hash<string> {
|
williamr@2
|
55 |
size_t operator()(const string& __s) const
|
williamr@2
|
56 |
{ return __stl_string_hash(__s); }
|
williamr@2
|
57 |
};
|
williamr@2
|
58 |
|
williamr@4
|
59 |
# if defined (_STLP_HAS_WCHAR_T)
|
williamr@4
|
60 |
_STLP_TEMPLATE_NULL
|
williamr@4
|
61 |
struct _STLP_CLASS_DECLSPEC hash<wstring> {
|
williamr@2
|
62 |
size_t operator()(const wstring& __s) const
|
williamr@2
|
63 |
{ return __stl_string_hash(__s); }
|
williamr@2
|
64 |
};
|
williamr@4
|
65 |
# endif
|
williamr@2
|
66 |
|
williamr@2
|
67 |
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@2
|
68 |
|
williamr@2
|
69 |
_STLP_END_NAMESPACE
|
williamr@2
|
70 |
|
williamr@2
|
71 |
#endif
|