/home/ntakagi/work/STLport-5.1.5/stlport/stl/_string_hash.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997-1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
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_INTERNAL_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   size_t __len = __s.size();
00037   const _CharT* __data = __s.data();
00038   for ( size_t __i = 0; __i < __len; ++__i)
00039     __h = /* 5 *__h */(__h << 2) + __h + __data[__i];
00040   return size_t(__h);
00041 }
00042 
00043 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
00044 
00045 template <class _CharT, class _Traits, class _Alloc>
00046 struct hash<basic_string<_CharT,_Traits,_Alloc> > {
00047   size_t operator()(const basic_string<_CharT,_Traits,_Alloc>& __s) const
00048     { return __stl_string_hash(__s); }
00049 };
00050 
00051 #else
00052 
00053 _STLP_TEMPLATE_NULL
00054 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
00061 struct _STLP_CLASS_DECLSPEC hash<wstring> {
00062   size_t operator()(const wstring& __s) const
00063     { return __stl_string_hash(__s); }
00064 };
00065 #  endif
00066 
00067 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
00068 
00069 _STLP_END_NAMESPACE
00070 
00071 #endif



Generated on Mon Mar 10 15:32:39 2008 by  doxygen 1.5.1