#include <string.h>
#include <stdarg.h>
-#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;
int i;
for (i = 0; i < size; i++)
hash_table[i] = (wxList *) NULL;
+*/
}
wxHashTable::~wxHashTable (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++)
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 wxChar *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)
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 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
{
wxObject *data = node->Data ();
delete node;
+ m_count--;
return data;
}
else
{
wxObject *data = node->Data ();
delete node;
+ m_count--;
return data;
}
else
{
wxObject *data = node->Data ();
delete node;
+ m_count--;
return data;
}
else
{
wxObject *data = node->Data ();
delete node;
+ m_count--;
return data;
}
else
void wxHashTable::DeleteContents (bool flag)
{
int i;
+ m_deleteContents = flag;
for (i = 0; i < n; i++)
{
if (hash_table[i])
if (hash_table[i])
hash_table[i]->Clear ();
}
+ m_count = 0;
}