// Created: 29/01/2002
// RCS-ID: $Id$
// Copyright: (c) Mattia Barbon
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Created: 29/01/2002
// RCS-ID: $Id$
// Copyright: (c) Mattia Barbon
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */
/* from requirements by Colin Plumb. */
/* (http://burtleburtle.net/bob/hash/doobs.html) */
/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */
/* from requirements by Colin Plumb. */
/* (http://burtleburtle.net/bob/hash/doobs.html) */
{
7ul, 13ul, 29ul,
53ul, 97ul, 193ul, 389ul, 769ul,
1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
{
7ul, 13ul, 29ul,
53ul, 97ul, 193ul, 389ul, 769ul,
1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
- 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
+ 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
1610612741ul, 3221225473ul, 4294967291ul
};
unsigned long _wxHashTableBase2::GetNextPrime( unsigned long n )
{
1610612741ul, 3221225473ul, 4294967291ul
};
unsigned long _wxHashTableBase2::GetNextPrime( unsigned long n )
{
- for( size_t i = 0; i < srcBuckets; ++i )
+ // 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( _wxHashTable_NodeBase* node = srcTable[i]; node; node = nextnode )
{
size_t bucket = func( dst, node );
nextnode = node->m_nxt;
_wxHashTable_NodeBase* newnode = proc( node );
for( _wxHashTable_NodeBase* node = srcTable[i]; node; node = nextnode )
{
size_t bucket = func( dst, node );
nextnode = node->m_nxt;
_wxHashTable_NodeBase* newnode = proc( node );
- newnode->m_nxt = dstTable[bucket];
- dstTable[bucket] = newnode;
+ 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;