]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/hash.cpp
more long/double to int conversion warnings from HP-UX logs fixed
[wxWidgets.git] / src / common / hash.cpp
index 3c514d498c9e8bd2b96e876ff36ef8bbd21c6f46..cfc590327ce3b1d1b60c21ffa599d8eeb07eb0c7 100644 (file)
@@ -36,6 +36,8 @@ 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;
@@ -104,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
@@ -176,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
@@ -196,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
@@ -212,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;
@@ -226,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
@@ -239,6 +259,7 @@ wxObject *wxHashTable::Delete (long key)
        {
          wxObject *data = node->Data ();
          delete node;
+         m_count--;
          return data;
        }
       else
@@ -249,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
@@ -258,6 +281,7 @@ wxObject *wxHashTable::Delete (const wxChar *key)
        {
          wxObject *data = node->Data ();
          delete node;
+         m_count--;
          return data;
        }
       else
@@ -268,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
@@ -282,6 +306,7 @@ wxObject *wxHashTable::Delete (long key, int value)
        {
          wxObject *data = node->Data ();
          delete node;
+         m_count--;
          return data;
        }
       else
@@ -292,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
@@ -301,6 +328,7 @@ wxObject *wxHashTable::Delete (long key, const wxChar *value)
        {
          wxObject *data = node->Data ();
          delete node;
+         m_count--;
          return data;
        }
       else
@@ -360,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])
@@ -375,5 +404,6 @@ void wxHashTable::Clear (void)
       if (hash_table[i])
        hash_table[i]->Clear ();
     }
+  m_count = 0;
 }