+ for (i = 0; i < n; i++)
+ {
+ if (hash_table[i])
+ hash_table[i]->Clear ();
+ }
+ }
+ m_count = 0;
+}
+
+#else // if !wxUSE_OLD_HASH_TABLE
+
+wxHashTableBase_Node::wxHashTableBase_Node( long key, void* value,
+ wxHashTableBase* table )
+ : m_value( value ), m_hashPtr( table )
+{
+ m_key.integer = key;
+}
+
+wxHashTableBase_Node::wxHashTableBase_Node( const wxChar* key, void* value,
+ wxHashTableBase* table )
+ : m_value( value ), m_hashPtr( table )
+{
+ m_key.string = wxStrcpy( new wxChar[wxStrlen( key ) + 1], key );
+}
+
+wxHashTableBase_Node::~wxHashTableBase_Node()
+{
+ if( m_hashPtr ) m_hashPtr->DoRemoveNode( this );
+}
+
+//
+
+wxHashTableBase::wxHashTableBase()
+ : m_size( 0 ), m_count( 0 ), m_table( NULL ), m_keyType( wxKEY_NONE ),
+ m_deleteContents( false )
+{
+}
+
+void wxHashTableBase::Create( wxKeyType keyType, size_t size )
+{
+ m_keyType = keyType;
+ m_size = size;
+ m_table = new wxHashTableBase_Node*[ m_size ];
+
+ for( size_t i = 0; i < m_size; ++i )
+ m_table[i] = NULL;
+}
+
+void wxHashTableBase::Clear()
+{
+ for( size_t i = 0; i < m_size; ++i )
+ {
+ Node* end = m_table[i];
+
+ if( end == NULL )
+ continue;
+
+ Node *curr, *next = end->GetNext();
+
+ do
+ {
+ curr = next;
+ next = curr->GetNext();
+
+ DoDestroyNode( curr );
+
+ delete curr;
+ }
+ while( curr != end );
+
+ m_table[i] = NULL;
+ }
+
+ m_count = 0;
+}
+
+void wxHashTableBase::DoRemoveNode( wxHashTableBase_Node* node )
+{
+ size_t bucket = ( m_keyType == wxKEY_INTEGER ?
+ node->m_key.integer :
+ MakeKey( node->m_key.string ) ) % m_size;
+
+ if( node->GetNext() == node )
+ {
+ // single-node chain (common case)
+ m_table[bucket] = NULL;
+ }
+ else
+ {
+ Node *start = m_table[bucket], *curr;
+ Node* prev = start;
+
+ for( curr = prev->GetNext(); curr != node;
+ prev = curr, curr = curr->GetNext() ) ;
+
+ DoUnlinkNode( bucket, node, prev );
+ }
+
+ DoDestroyNode( node );
+}
+
+void wxHashTableBase::DoDestroyNode( wxHashTableBase_Node* node )
+{
+ // if it is called from DoRemoveNode, node has already been
+ // removed, from other places it does not matter
+ node->m_hashPtr = NULL;
+
+ if( m_keyType == wxKEY_STRING )
+ delete[] node->m_key.string;
+ if( m_deleteContents )
+ DoDeleteContents( node );
+}
+
+void wxHashTableBase::Destroy()
+{
+ Clear();
+
+ delete[] m_table;
+
+ m_table = NULL;
+ m_size = 0;
+}
+
+void wxHashTableBase::DoInsertNode( size_t bucket, wxHashTableBase_Node* node )
+{
+ if( m_table[bucket] == NULL )
+ {
+ m_table[bucket] = node->m_next = node;
+ }
+ else
+ {
+ Node *prev = m_table[bucket];
+ Node *next = prev->m_next;
+
+ prev->m_next = node;
+ node->m_next = next;
+ m_table[bucket] = node;
+ }
+
+ ++m_count;
+}
+
+void wxHashTableBase::DoPut( long key, long hash, void* data )
+{
+ wxASSERT( m_keyType == wxKEY_INTEGER );
+
+ size_t bucket = size_t(hash) % m_size;
+ Node* node = new wxHashTableBase_Node( key, data, this );
+
+ DoInsertNode( bucket, node );
+}
+
+void wxHashTableBase::DoPut( const wxChar* key, long hash, void* data )
+{
+ wxASSERT( m_keyType == wxKEY_STRING );
+
+ size_t bucket = size_t(hash) % m_size;
+ Node* node = new wxHashTableBase_Node( key, data, this );
+
+ DoInsertNode( bucket, node );
+}
+
+void* wxHashTableBase::DoGet( long key, long hash ) const
+{
+ wxASSERT( m_keyType == wxKEY_INTEGER );
+
+ size_t bucket = size_t(hash) % m_size;
+
+ if( m_table[bucket] == NULL )
+ return NULL;
+
+ Node *first = m_table[bucket]->GetNext(),
+ *curr = first;
+
+ do
+ {
+ if( curr->m_key.integer == key )
+ return curr->m_value;
+
+ curr = curr->GetNext();