/////////////////////////////////////////////////////////////////////////////
-// Name: hashmap.cpp
+// Name: src/common/hashmap.cpp
// Purpose: wxHashMap implementation
// Author: Mattia Barbon
-// Modified by:
+// Modified by:
// Created: 29/01/2002
// RCS-ID: $Id$
// Copyright: (c) Mattia Barbon
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
-#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"
-#include <assert.h>
-
/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */
/* 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<typename T>
+static unsigned long DoStringHash(T *k)
{
unsigned long hash = 0;
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)
/* from SGI STL */
-const unsigned long _wxHashTableBase2::s_primes[prime_count] =
+const unsigned long _wxHashTableBase2::ms_primes[prime_count] =
{
7ul, 13ul, 29ul,
53ul, 97ul, 193ul, 389ul, 769ul,
unsigned long _wxHashTableBase2::GetNextPrime( unsigned long n )
{
- const unsigned long* ptr = &s_primes[0];
+ const unsigned long* ptr = &ms_primes[0];
for( size_t i = 0; i < prime_count; ++i, ++ptr )
{
if( n < *ptr )
}
/* someone might try to alloc a 2^32-element hash table */
- assert(0);
+ wxFAIL_MSG( _T("hash table too big?") );
+
/* quiet warning */
return 0;
}
unsigned long _wxHashTableBase2::GetPreviousPrime( unsigned long n )
{
- const unsigned long* ptr = &s_primes[prime_count - 1];
+ const unsigned long* ptr = &ms_primes[prime_count - 1];
for( size_t i = 0; i < prime_count; ++i, --ptr )
{
while( node )
{
- tmp = node->m_nxt;
+ tmp = node->m_next;
dtor( node );
node = tmp;
}
{
size_t bucket = func( dst, node );
- nextnode = node->m_nxt;
+ nextnode = node->m_next;
_wxHashTable_NodeBase* newnode = proc( node );
- newnode->m_nxt = dstTable[bucket];
+ newnode->m_next = dstTable[bucket];
dstTable[bucket] = newnode;
}
}
return node;
}
+#endif // !wxUSE_STL || !defined(HAVE_STL_HASH_MAP)