From ad78ab8c50af53094c302f676719621ce9867fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 28 Mar 2007 09:46:46 +0000 Subject: [PATCH] made wxHashMap work with any form of strings git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45097 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/hashmap.h | 26 +++++++++++++++++--------- src/common/hashmap.cpp | 22 ++++++---------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index 41aaccb230..7f7cc6a97f 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -561,21 +561,29 @@ public: wxPointerEqual& operator=(const wxPointerEqual&) { return *this; } }; -// wxString, char*, wxChar* +// wxString, char*, wchar_t* class WXDLLIMPEXP_BASE wxStringHash { public: wxStringHash() {} unsigned long operator()( const wxString& x ) const - { return wxCharStringHash( x.c_str() ); } - unsigned long operator()( const wxChar* x ) const - { return wxCharStringHash( x ); } - static unsigned long wxCharStringHash( const wxChar* ); -#if wxUSE_UNICODE + { return stringHash( x.wx_str() ); } + unsigned long operator()( const wchar_t* x ) const + { return stringHash( x ); } unsigned long operator()( const char* x ) const - { return charStringHash( x ); } - static unsigned long charStringHash( const char* ); -#endif // wxUSE_UNICODE + { return stringHash( x ); } + +#if WXWIN_COMPATIBILITY_2_8 + static unsigned long wxCharStringHash( const wxChar* x ) + { return stringHash(x); } + #if wxUSE_UNICODE + static unsigned long charStringHash( const char* x ) + { return stringHash(x); } + #endif +#endif // WXWIN_COMPATIBILITY_2_8 + + static unsigned long stringHash( const wchar_t* ); + static unsigned long stringHash( const char* ); wxStringHash& operator=(const wxStringHash&) { return *this; } }; diff --git a/src/common/hashmap.cpp b/src/common/hashmap.cpp index 6612272118..de00f58cab 100644 --- a/src/common/hashmap.cpp +++ b/src/common/hashmap.cpp @@ -22,7 +22,8 @@ /* from requirements by Colin Plumb. */ /* (http://burtleburtle.net/bob/hash/doobs.html) */ /* adapted from Perl sources ( hv.h ) */ -unsigned long wxStringHash::wxCharStringHash( const wxChar* k ) +template +static unsigned long DoStringHash(T *k) { unsigned long hash = 0; @@ -38,23 +39,12 @@ unsigned long wxStringHash::wxCharStringHash( const wxChar* k ) return hash + (hash << 15); } -#if wxUSE_UNICODE -unsigned long wxStringHash::charStringHash( const char* k ) -{ - unsigned long hash = 0; +unsigned long wxStringHash::stringHash( const char* k ) + { return DoStringHash(k); } - while( *k ) - { - hash += *k++; - hash += (hash << 10); - hash ^= (hash >> 6); - } - hash += (hash << 3); - hash ^= (hash >> 11); +unsigned long wxStringHash::stringHash( const wchar_t* k ) + { return DoStringHash(k); } - return hash + (hash << 15); -} -#endif #if !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)