X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ad81651f00edc6f489d9b6a0839d316a964fd521..794bcc2dea743ac907b839f54e451847c9ea4b72:/src/common/hash.cpp?ds=sidebyside diff --git a/src/common/hash.cpp b/src/common/hash.cpp index fbee85aceb..cfc590327c 100644 --- a/src/common/hash.cpp +++ b/src/common/hash.cpp @@ -33,6 +33,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxHashTable, wxObject) 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; @@ -42,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) @@ -62,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++) @@ -99,62 +106,79 @@ void wxHashTable::Put (long key, long value, wxObject * object) { // Should NEVER be long k = (long) key; - if (k < 0) - k = -k; int position = (int) (k % n); + if (position < 0) position = -position; + 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 wxChar *value, wxObject * object) { // Should NEVER be - long k = (long) key; - if (k < 0) - k = -k; + long k = (long) key; int position = (int) (k % n); + if (position < 0) position = -position; + 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) { // Should NEVER be long k = (long) key; - if (k < 0) - k = -k; - + int position = (int) (k % n); + if (position < 0) position = -position; + 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 wxChar *key, wxObject * object) { int position = (int) (MakeKey (key) % n); + if (position < 0) position = -position; 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 { // Should NEVER be long k = (long) key; - if (k < 0) - k = -k; int position = (int) (k % n); + if (position < 0) position = -position; + if (!hash_table[position]) return (wxObject *) NULL; else @@ -171,10 +195,10 @@ wxObject *wxHashTable::Get (long key, const wxChar *value) const { // Should NEVER be long k = (long) key; - if (k < 0) - k = -k; - + int position = (int) (k % n); + if (position < 0) position = -position; + if (!hash_table[position]) return (wxObject *) NULL; else @@ -191,10 +215,10 @@ wxObject *wxHashTable::Get (long key) const { // Should NEVER be long k = (long) key; - if (k < 0) - k = -k; int position = (int) (k % n); + if (position < 0) position = -position; + if (!hash_table[position]) return (wxObject *) NULL; else @@ -207,6 +231,7 @@ wxObject *wxHashTable::Get (long key) const wxObject *wxHashTable::Get (const wxChar *key) const { int position = (int) (MakeKey (key) % n); + if (position < 0) position = -position; if (!hash_table[position]) return (wxObject *) NULL; @@ -221,10 +246,10 @@ wxObject *wxHashTable::Delete (long key) { // Should NEVER be long k = (long) key; - if (k < 0) - k = -k; int position = (int) (k % n); + if (position < 0) position = -position; + if (!hash_table[position]) return (wxObject *) NULL; else @@ -234,6 +259,7 @@ wxObject *wxHashTable::Delete (long key) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -244,6 +270,8 @@ wxObject *wxHashTable::Delete (long key) wxObject *wxHashTable::Delete (const wxChar *key) { int position = (int) (MakeKey (key) % n); + if (position < 0) position = -position; + if (!hash_table[position]) return (wxObject *) NULL; else @@ -253,6 +281,7 @@ wxObject *wxHashTable::Delete (const wxChar *key) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -263,11 +292,11 @@ wxObject *wxHashTable::Delete (const wxChar *key) wxObject *wxHashTable::Delete (long key, int value) { // Should NEVER be - long k = (long) key; - if (k < 0) - k = -k; + long k = (long) key; int position = (int) (k % n); + if (position < 0) position = -position; + if (!hash_table[position]) return (wxObject *) NULL; else @@ -277,6 +306,7 @@ wxObject *wxHashTable::Delete (long key, int value) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -287,6 +317,8 @@ wxObject *wxHashTable::Delete (long key, int value) wxObject *wxHashTable::Delete (long key, const wxChar *value) { int position = (int) (key % n); + if (position < 0) position = -position; + if (!hash_table[position]) return (wxObject *) NULL; else @@ -296,6 +328,7 @@ wxObject *wxHashTable::Delete (long key, const wxChar *value) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -355,6 +388,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]) @@ -370,5 +404,6 @@ void wxHashTable::Clear (void) if (hash_table[i]) hash_table[i]->Clear (); } + m_count = 0; }