00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _STLP_STRING_HASH_H
00020 # define _STLP_STRING_HASH_H
00021
00022 #ifndef _STLP_HASH_FUN_H
00023 # include <stl/_hash_fun.h>
00024 #endif
00025
00026 #ifndef _STLP_STRING_H
00027 # include <stl/_string.h>
00028 #endif
00029
00030 _STLP_BEGIN_NAMESPACE
00031
00032 template <class _CharT, class _Traits, class _Alloc>
00033 _STLP_INLINE_LOOP size_t
00034 __stl_string_hash(const basic_string<_CharT,_Traits,_Alloc>& __s) {
00035 unsigned long __h = 0;
00036 typedef typename basic_string<_CharT,_Traits,_Alloc>::const_pointer const_ptr;
00037 size_t __len = __s.size();
00038 const _CharT* __data = __s.data();
00039 for ( size_t __i = 0; __i < __len; ++__i)
00040 __h = 5*__h + __data[__i];
00041 return size_t(__h);
00042 }
00043
00044 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
00045
00046 template <class _CharT, class _Traits, class _Alloc>
00047 struct hash<basic_string<_CharT,_Traits,_Alloc> > {
00048 size_t operator()(const basic_string<_CharT,_Traits,_Alloc>& __s) const
00049 { return __stl_string_hash(__s); }
00050 };
00051
00052 #else
00053
00054 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC hash<string> {
00055 size_t operator()(const string& __s) const
00056 { return __stl_string_hash(__s); }
00057 };
00058
00059 # if defined (_STLP_HAS_WCHAR_T)
00060 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC hash<wstring> {
00061 size_t operator()(const wstring& __s) const
00062 { return __stl_string_hash(__s); }
00063 };
00064 # endif
00065
00066 #endif
00067
00068 _STLP_END_NAMESPACE
00069
00070 #endif