X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd83cb56d29385e2a87840eeb3876b976a5afc43..d2b354f9c9f1473b2d6ff0ab643ebf57dcbfb656:/src/common/hash.cpp diff --git a/src/common/hash.cpp b/src/common/hash.cpp index 09e9b42d13..1df6c30b78 100644 --- a/src/common/hash.cpp +++ b/src/common/hash.cpp @@ -5,7 +5,7 @@ // Modified by: VZ at 25.02.00: type safe hashes with WX_DECLARE_HASH() // Created: 01/02/97 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem +// Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -34,6 +34,8 @@ #include "wx/hash.h" +#if !wxUSE_STL + #include #include @@ -119,6 +121,8 @@ wxNodeBase *wxHashTableBase::GetNode(long key, long value) const return node; } +#if WXWIN_COMPATIBILITY_2_4 + // ---------------------------------------------------------------------------- // wxHashTableLong // ---------------------------------------------------------------------------- @@ -143,6 +147,11 @@ void wxHashTableLong::Init(size_t size) m_count = 0; } +void wxHashTableLong::Create(size_t size) +{ + Init(size); +} + void wxHashTableLong::Destroy() { for ( size_t n = 0; n < m_hashSize; n++ ) @@ -305,6 +314,32 @@ wxString wxStringHashTable::Get(long key, bool *wasFound) const return _T(""); } +bool wxStringHashTable::Delete(long key) const +{ + wxCHECK_MSG( m_hashSize, FALSE, _T("must call Create() first") ); + + size_t slot = (size_t)abs((int)(key % (long)m_hashSize)); + + wxArrayLong *keys = m_keys[slot]; + if ( keys ) + { + size_t count = keys->GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + if ( keys->Item(n) == key ) + { + keys->RemoveAt(n); + m_values[slot]->RemoveAt(n); + return TRUE; + } + } + } + + return FALSE; +} + +#endif // WXWIN_COMPATIBILITY_2_4 + // ---------------------------------------------------------------------------- // old not type safe wxHashTable // ---------------------------------------------------------------------------- @@ -365,6 +400,7 @@ bool wxHashTable::Create(int the_key_type, int size) void wxHashTable::DoCopy(const wxHashTable& table) { n = table.n; + m_count = table.m_count; current_position = table.current_position; current_node = NULL; // doesn't matter - Next() will reconstruct it key_type = table.key_type; @@ -408,7 +444,7 @@ void wxHashTable::Put (long key, const wxChar *value, wxObject * object) if (!hash_table[position]) { - hash_table[position] = new wxList (wxKEY_INTEGER); + hash_table[position] = new wxList (wxKEY_STRING); if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); } @@ -463,7 +499,7 @@ wxObject *wxHashTable::Get (long key, long value) const { wxNode *node = hash_table[position]->Find (value); if (node) - return node->Data (); + return node->GetData (); else return (wxObject *) NULL; } @@ -483,7 +519,7 @@ wxObject *wxHashTable::Get (long key, const wxChar *value) const { wxNode *node = hash_table[position]->Find (value); if (node) - return node->Data (); + return node->GetData (); else return (wxObject *) NULL; } @@ -502,7 +538,7 @@ wxObject *wxHashTable::Get (long key) const else { wxNode *node = hash_table[position]->Find (k); - return node ? node->Data () : (wxObject*)NULL; + return node ? node->GetData () : (wxObject*)NULL; } } @@ -516,7 +552,7 @@ wxObject *wxHashTable::Get (const wxChar *key) const else { wxNode *node = hash_table[position]->Find (key); - return node ? node->Data () : (wxObject*)NULL; + return node ? node->GetData () : (wxObject*)NULL; } } @@ -535,7 +571,7 @@ wxObject *wxHashTable::Delete (long key) wxNode *node = hash_table[position]->Find (k); if (node) { - wxObject *data = node->Data (); + wxObject *data = node->GetData (); delete node; m_count--; return data; @@ -557,7 +593,7 @@ wxObject *wxHashTable::Delete (const wxChar *key) wxNode *node = hash_table[position]->Find (key); if (node) { - wxObject *data = node->Data (); + wxObject *data = node->GetData (); delete node; m_count--; return data; @@ -582,7 +618,7 @@ wxObject *wxHashTable::Delete (long key, int value) wxNode *node = hash_table[position]->Find (value); if (node) { - wxObject *data = node->Data (); + wxObject *data = node->GetData (); delete node; m_count--; return data; @@ -604,7 +640,7 @@ wxObject *wxHashTable::Delete (long key, const wxChar *value) wxNode *node = hash_table[position]->Find (value); if (node) { - wxObject *data = node->Data (); + wxObject *data = node->GetData (); delete node; m_count--; return data; @@ -649,14 +685,14 @@ wxNode *wxHashTable::Next () { if (hash_table[current_position]) { - current_node = hash_table[current_position]->First (); + current_node = hash_table[current_position]->GetFirst (); found = current_node; } } } else { - current_node = current_node->Next (); + current_node = current_node->GetNext (); found = current_node; } } @@ -676,12 +712,16 @@ void wxHashTable::DeleteContents (bool flag) void wxHashTable::Clear () { - int i; - for (i = 0; i < n; i++) + int i; + if (hash_table) { - if (hash_table[i]) - hash_table[i]->Clear (); + for (i = 0; i < n; i++) + { + if (hash_table[i]) + hash_table[i]->Clear (); + } } m_count = 0; } +#endif // !wxUSE_STL