williamr@4: /* williamr@4: * Copyright (c) 1997-1999 williamr@4: * Silicon Graphics Computer Systems, Inc. williamr@4: * williamr@4: * Copyright (c) 1999 williamr@4: * Boris Fomitchev williamr@4: * williamr@4: * This material is provided "as is", with absolutely no warranty expressed williamr@4: * or implied. Any use is at your own risk. williamr@4: * williamr@4: * Permission to use or copy this software for any purpose is hereby granted williamr@4: * without fee, provided the above notices are retained on all copies. williamr@4: * Permission to modify the code and to distribute modified code is granted, williamr@4: * provided the above notices are retained, and a notice that the code was williamr@4: * modified is included with the above copyright notice. williamr@4: * williamr@4: */ williamr@4: williamr@4: #ifndef _STLP_STRING_HASH_H williamr@4: # define _STLP_STRING_HASH_H williamr@4: williamr@4: #ifndef _STLP_HASH_FUN_H williamr@4: # include williamr@4: #endif williamr@4: williamr@4: #ifndef _STLP_STRING_H williamr@4: # include williamr@4: #endif williamr@4: williamr@4: _STLP_BEGIN_NAMESPACE williamr@4: williamr@4: template williamr@4: _STLP_INLINE_LOOP size_t williamr@4: __stl_string_hash(const basic_string<_CharT,_Traits,_Alloc>& __s) { williamr@4: unsigned long __h = 0; williamr@4: typedef typename basic_string<_CharT,_Traits,_Alloc>::const_pointer const_ptr; williamr@4: size_t __len = __s.size(); williamr@4: const _CharT* __data = __s.data(); williamr@4: for ( size_t __i = 0; __i < __len; ++__i) williamr@4: __h = 5*__h + __data[__i]; williamr@4: return size_t(__h); williamr@4: } williamr@4: williamr@4: #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION williamr@4: williamr@4: template williamr@4: struct hash > { williamr@4: size_t operator()(const basic_string<_CharT,_Traits,_Alloc>& __s) const williamr@4: { return __stl_string_hash(__s); } williamr@4: }; williamr@4: williamr@4: #else williamr@4: williamr@4: _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC hash { williamr@4: size_t operator()(const string& __s) const williamr@4: { return __stl_string_hash(__s); } williamr@4: }; williamr@4: williamr@4: # if defined (_STLP_HAS_WCHAR_T) williamr@4: _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC hash { williamr@4: size_t operator()(const wstring& __s) const williamr@4: { return __stl_string_hash(__s); } williamr@4: }; williamr@4: # endif williamr@4: williamr@4: #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */ williamr@4: williamr@4: _STLP_END_NAMESPACE williamr@4: williamr@4: #endif