X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5692876f3b45c8f141ea961f0a206b0c2248bc6d..794bcc2dea743ac907b839f54e451847c9ea4b72:/src/common/hash.cpp diff --git a/src/common/hash.cpp b/src/common/hash.cpp index 4c6ad97c6d..cfc590327c 100644 --- a/src/common/hash.cpp +++ b/src/common/hash.cpp @@ -37,6 +37,7 @@ wxHashTable::wxHashTable (int the_key_type, int size) hash_table = (wxList**) NULL; Create(the_key_type, size); m_count = 0; + m_deleteContents = FALSE; /* n = size; current_position = -1; @@ -105,12 +106,15 @@ 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++; @@ -119,13 +123,16 @@ void wxHashTable::Put (long key, long value, wxObject * object) 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++; @@ -135,13 +142,16 @@ 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++; } @@ -149,9 +159,13 @@ void wxHashTable::Put (long key, wxObject * object) 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++; @@ -161,10 +175,10 @@ 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 @@ -181,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 @@ -201,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 @@ -217,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; @@ -231,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 @@ -255,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 @@ -275,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 @@ -300,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 @@ -369,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])