_string_hash.h

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_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 /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
00067 
00068 _STLP_END_NAMESPACE
00069 
00070 #endif

Generated on Mon Jun 5 10:20:47 2006 for Intelligence.kdevelop by  doxygen 1.4.6