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