X-Git-Url: http://git.buserror.net/cgi-bin/gitweb.cgi?p=polintos%2Fscott%2Fpriv.git;a=blobdiff_plain;f=include%2Fc%2B%2B%2Fstl%2Fstl%2F_string_hash.h;fp=include%2Fc%2B%2B%2Fstl%2Fstl%2F_string_hash.h;h=c5f133926d5b45037d3de53d59d67673d8221ed5;hp=0000000000000000000000000000000000000000;hb=173d8903eb9d51a4ea7d7fa3e52dc86c9bb6d4f1;hpb=b024710fe2b60cd4a42a8993b61333d6cdb56ca3 diff --git a/include/c++/stl/stl/_string_hash.h b/include/c++/stl/stl/_string_hash.h new file mode 100644 index 0000000..c5f1339 --- /dev/null +++ b/include/c++/stl/stl/_string_hash.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1997-1999 + * Silicon Graphics Computer Systems, Inc. + * + * Copyright (c) 1999 + * Boris Fomitchev + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +#ifndef _STLP_STRING_HASH_H +#define _STLP_STRING_HASH_H + +#ifndef _STLP_HASH_FUN_H +# include +#endif + +#ifndef _STLP_INTERNAL_STRING_H +# include +#endif + +_STLP_BEGIN_NAMESPACE + +template +_STLP_INLINE_LOOP size_t +__stl_string_hash(const basic_string<_CharT,_Traits,_Alloc>& __s) { + unsigned long __h = 0; + size_t __len = __s.size(); + const _CharT* __data = __s.data(); + for ( size_t __i = 0; __i < __len; ++__i) + __h = /* 5 *__h */(__h << 2) + __h + __data[__i]; + return size_t(__h); +} + +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) + +template +struct hash > { + size_t operator()(const basic_string<_CharT,_Traits,_Alloc>& __s) const + { return __stl_string_hash(__s); } +}; + +#else + +_STLP_TEMPLATE_NULL +struct _STLP_CLASS_DECLSPEC hash { + size_t operator()(const string& __s) const + { return __stl_string_hash(__s); } +}; + +# if defined (_STLP_HAS_WCHAR_T) +_STLP_TEMPLATE_NULL +struct _STLP_CLASS_DECLSPEC hash { + size_t operator()(const wstring& __s) const + { return __stl_string_hash(__s); } +}; +# endif + +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */ + +_STLP_END_NAMESPACE + +#endif