X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8ae94823a3bf377614a5a67f750545217b6f6b8d..0f5378d414cb68caaa535199c1af12dec1720c3d:/src/common/hashmap.cpp?ds=inline diff --git a/src/common/hashmap.cpp b/src/common/hashmap.cpp index 098d789ac7..66f14e5815 100644 --- a/src/common/hashmap.cpp +++ b/src/common/hashmap.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: hashmap.cpp +// Name: src/common/hashmap.cpp // Purpose: wxHashMap implementation // Author: Mattia Barbon // Modified by: @@ -9,15 +9,11 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "hashmap.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #include "wx/hashmap.h" @@ -26,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; @@ -42,23 +39,14 @@ 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 + +#ifdef wxNEEDS_WX_HASH_MAP /* from SGI STL */ const unsigned long _wxHashTableBase2::ms_primes[prime_count] = @@ -82,7 +70,7 @@ unsigned long _wxHashTableBase2::GetNextPrime( unsigned long n ) } /* someone might try to alloc a 2^32-element hash table */ - wxFAIL_MSG( _T("hash table too big?") ); + wxFAIL_MSG( wxT("hash table too big?") ); /* quiet warning */ return 0; @@ -115,7 +103,7 @@ void _wxHashTableBase2::DeleteNodes( size_t buckets, while( node ) { - tmp = node->m_nxt; + tmp = node->m_next; dtor( node ); node = tmp; } @@ -128,20 +116,9 @@ void _wxHashTableBase2::CopyHashTable( _wxHashTable_NodeBase** srcTable, size_t srcBuckets, _wxHashTableBase2* dst, _wxHashTable_NodeBase** dstTable, - size_t dstBuckets, BucketFromNode func, ProcessNode proc ) { - // for compatibility with wxHashTable (to avoid reimplementig it - // from scratch), we need to preserve the order of nodes in a - // source bucket when copying the table, hence, to avoid - // allocating an auxiliary table we use a circular list for each - // bucket, and we keep the *tail* of each list in dstTable[i], to - // be able to append nodes in O(1) time. Wen we're done copying, - // we adjust dstTable[i] to point at the head of the list and we - // break the circular list into a linear one. - size_t i; - - for( i = 0; i < srcBuckets; ++i ) + for( size_t i = 0; i < srcBuckets; ++i ) { _wxHashTable_NodeBase* nextnode; @@ -149,26 +126,10 @@ void _wxHashTableBase2::CopyHashTable( _wxHashTable_NodeBase** srcTable, { size_t bucket = func( dst, node ); - nextnode = node->m_nxt; + nextnode = node->m_next; _wxHashTable_NodeBase* newnode = proc( node ); - if( dstTable[bucket] ) - { - newnode->m_nxt = dstTable[bucket]->m_nxt; // head of the list - dstTable[bucket]->m_nxt = newnode; - dstTable[bucket] = newnode; - } - else - dstTable[bucket] = newnode->m_nxt = newnode; - } - } - - for( i = 0; i < dstBuckets; ++i ) - { - if( dstTable[i] ) - { - _wxHashTable_NodeBase* tmp = dstTable[i]; - dstTable[i] = dstTable[i]->m_nxt; - tmp->m_nxt = NULL; + newnode->m_next = dstTable[bucket]; + dstTable[bucket] = newnode; } } } @@ -178,3 +139,4 @@ _wxHashTable_NodeBase* _wxHashTableBase2::DummyProcessNode(_wxHashTable_NodeBase return node; } +#endif // wxNEEDS_WX_HASH_MAP