X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e55ad60e195f1007db921b2a73a3cac98ed9df65..d2fdd8d2af20f032b26562fc5eb0af2c85d5c8b6:/src/common/hash.cpp diff --git a/src/common/hash.cpp b/src/common/hash.cpp index 69b17fd56e..5110f8228c 100644 --- a/src/common/hash.cpp +++ b/src/common/hash.cpp @@ -29,12 +29,16 @@ #include #include -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxHashTable, wxObject) -#endif wxHashTable::wxHashTable (int the_key_type, int size) { + n = 0; + hash_table = (wxList**) NULL; + Create(the_key_type, size); + m_count = 0; + m_deleteContents = FALSE; +/* n = size; current_position = -1; current_node = (wxNode *) NULL; @@ -44,6 +48,7 @@ wxHashTable::wxHashTable (int the_key_type, int size) int i; for (i = 0; i < size; i++) hash_table[i] = (wxList *) NULL; +*/ } wxHashTable::~wxHashTable (void) @@ -64,13 +69,13 @@ void wxHashTable::Destroy(void) bool wxHashTable::Create(int the_key_type, int size) { + Destroy(); + n = size; current_position = -1; current_node = (wxNode *) NULL; key_type = the_key_type; - if (hash_table) - delete[] hash_table; hash_table = new wxList *[size]; int i; for (i = 0; i < size; i++) @@ -78,6 +83,25 @@ bool wxHashTable::Create(int the_key_type, int size) return TRUE; } + +void wxHashTable::DoCopy(const wxHashTable& table) +{ + n = table.n; + current_position = table.current_position; + current_node = NULL; // doesn't matter - Next() will reconstruct it + key_type = table.key_type; + + hash_table = new wxList *[n]; + for (int i = 0; i < n; i++) { + if (table.hash_table[i] == NULL) + hash_table[i] = NULL; + else { + hash_table[i] = new wxList(key_type); + *(hash_table[i]) = *(table.hash_table[i]); + } + } +} + void wxHashTable::Put (long key, long value, wxObject * object) { // Should NEVER be @@ -87,12 +111,16 @@ void wxHashTable::Put (long key, long value, wxObject * object) int position = (int) (k % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_INTEGER); + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } hash_table[position]->Append (value, object); + m_count++; } -void wxHashTable::Put (long key, const char *value, wxObject * object) +void wxHashTable::Put (long key, const wxChar *value, wxObject * object) { // Should NEVER be long k = (long) key; @@ -101,9 +129,13 @@ void wxHashTable::Put (long key, const char *value, wxObject * object) int position = (int) (k % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_INTEGER); + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } hash_table[position]->Append (value, object); + m_count++; } void wxHashTable::Put (long key, wxObject * object) @@ -115,19 +147,27 @@ void wxHashTable::Put (long key, wxObject * object) int position = (int) (k % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_INTEGER); - + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } + hash_table[position]->Append (k, object); + m_count++; } -void wxHashTable::Put (const char *key, wxObject * object) +void wxHashTable::Put (const wxChar *key, wxObject * object) { int position = (int) (MakeKey (key) % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_STRING); + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } hash_table[position]->Append (key, object); + m_count++; } wxObject *wxHashTable::Get (long key, long value) const @@ -150,7 +190,7 @@ wxObject *wxHashTable::Get (long key, long value) const } } -wxObject *wxHashTable::Get (long key, const char *value) const +wxObject *wxHashTable::Get (long key, const wxChar *value) const { // Should NEVER be long k = (long) key; @@ -187,7 +227,7 @@ wxObject *wxHashTable::Get (long key) const } } -wxObject *wxHashTable::Get (const char *key) const +wxObject *wxHashTable::Get (const wxChar *key) const { int position = (int) (MakeKey (key) % n); @@ -217,6 +257,7 @@ wxObject *wxHashTable::Delete (long key) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -224,7 +265,7 @@ wxObject *wxHashTable::Delete (long key) } } -wxObject *wxHashTable::Delete (const char *key) +wxObject *wxHashTable::Delete (const wxChar *key) { int position = (int) (MakeKey (key) % n); if (!hash_table[position]) @@ -236,6 +277,7 @@ wxObject *wxHashTable::Delete (const char *key) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -260,6 +302,7 @@ wxObject *wxHashTable::Delete (long key, int value) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -267,7 +310,7 @@ wxObject *wxHashTable::Delete (long key, int value) } } -wxObject *wxHashTable::Delete (long key, const char *value) +wxObject *wxHashTable::Delete (long key, const wxChar *value) { int position = (int) (key % n); if (!hash_table[position]) @@ -279,6 +322,7 @@ wxObject *wxHashTable::Delete (long key, const char *value) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -286,12 +330,12 @@ wxObject *wxHashTable::Delete (long key, const char *value) } } -long wxHashTable::MakeKey (const char *string) const +long wxHashTable::MakeKey (const wxChar *string) const { long int_key = 0; while (*string) - int_key += (unsigned char) *string++; + int_key += (wxUChar) *string++; return int_key; } @@ -338,6 +382,7 @@ wxNode *wxHashTable::Next (void) void wxHashTable::DeleteContents (bool flag) { int i; + m_deleteContents = flag; for (i = 0; i < n; i++) { if (hash_table[i]) @@ -353,5 +398,6 @@ void wxHashTable::Clear (void) if (hash_table[i]) hash_table[i]->Clear (); } + m_count = 0; }