From 5692876f3b45c8f141ea961f0a206b0c2248bc6d Mon Sep 17 00:00:00 2001 From: "Bart A.M. Jourquin" Date: Tue, 11 Jan 2000 16:19:35 +0000 Subject: [PATCH] Adding GetCount() to wxHashTable git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5341 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/hash.h | 6 ++++++ src/common/hash.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/wx/hash.h b/include/wx/hash.h index 4634f96313..2e17fb019c 100644 --- a/include/wx/hash.h +++ b/include/wx/hash.h @@ -99,6 +99,12 @@ class WXDLLEXPORT wxHashTable: public wxObject void DeleteContents(bool flag); void Clear(void); + // Returns number of nodes + size_t GetCount() const { return m_count; } + + private: + size_t m_count; // number of elements in the hashtable + }; #endif diff --git a/src/common/hash.cpp b/src/common/hash.cpp index 3c514d498c..4c6ad97c6d 100644 --- a/src/common/hash.cpp +++ b/src/common/hash.cpp @@ -36,6 +36,7 @@ wxHashTable::wxHashTable (int the_key_type, int size) n = 0; hash_table = (wxList**) NULL; Create(the_key_type, size); + m_count = 0; /* n = size; current_position = -1; @@ -112,6 +113,7 @@ void wxHashTable::Put (long key, long value, wxObject * object) hash_table[position] = new wxList (wxKEY_INTEGER); hash_table[position]->Append (value, object); + m_count++; } void wxHashTable::Put (long key, const wxChar *value, wxObject * object) @@ -126,6 +128,7 @@ void wxHashTable::Put (long key, const wxChar *value, wxObject * object) hash_table[position] = new wxList (wxKEY_INTEGER); hash_table[position]->Append (value, object); + m_count++; } void wxHashTable::Put (long key, wxObject * object) @@ -140,6 +143,7 @@ void wxHashTable::Put (long key, wxObject * object) hash_table[position] = new wxList (wxKEY_INTEGER); hash_table[position]->Append (k, object); + m_count++; } void wxHashTable::Put (const wxChar *key, wxObject * object) @@ -150,6 +154,7 @@ void wxHashTable::Put (const wxChar *key, wxObject * object) hash_table[position] = new wxList (wxKEY_STRING); hash_table[position]->Append (key, object); + m_count++; } wxObject *wxHashTable::Get (long key, long value) const @@ -239,6 +244,7 @@ wxObject *wxHashTable::Delete (long key) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -258,6 +264,7 @@ wxObject *wxHashTable::Delete (const wxChar *key) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -282,6 +289,7 @@ wxObject *wxHashTable::Delete (long key, int value) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -301,6 +309,7 @@ wxObject *wxHashTable::Delete (long key, const wxChar *value) { wxObject *data = node->Data (); delete node; + m_count--; return data; } else @@ -375,5 +384,6 @@ void wxHashTable::Clear (void) if (hash_table[i]) hash_table[i]->Clear (); } + m_count = 0; } -- 2.45.2