2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: hash.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxHashTable
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxHashTable
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-11-03 14:37:14 +00:00
|
|
|
@deprecated
|
|
|
|
Please note that this class is retained for backward compatibility
|
2008-03-08 13:52:38 +00:00
|
|
|
reasons; you should use wxHashMap.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
This class provides hash table functionality for wxWidgets, and for an
|
2008-11-03 14:37:14 +00:00
|
|
|
application if it wishes. Data can be hashed on an integer or string key.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
@code
|
|
|
|
wxHashTable table(wxKEY_STRING);
|
|
|
|
|
|
|
|
wxPoint *point = new wxPoint(100, 200);
|
|
|
|
table.Put("point 1", point);
|
|
|
|
|
|
|
|
....
|
|
|
|
|
|
|
|
wxPoint *found_point = (wxPoint *)table.Get("point 1");
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
A hash table is implemented as an array of pointers to lists.
|
|
|
|
When no data has been stored, the hash table takes only a little more space
|
|
|
|
than this array (default size is 1000). When a data item is added, an integer
|
|
|
|
is constructed from the integer or string key that is within the bounds of the array.
|
|
|
|
If the array element is @NULL, a new (keyed) list is created for the element.
|
|
|
|
Then the data object is appended to the list, storing the key in case other
|
|
|
|
data objects need to be stored in the list also (when a 'collision' occurs).
|
|
|
|
|
|
|
|
Retrieval involves recalculating the array index from the key, and searching
|
|
|
|
along the keyed list for the data object whose stored key matches the passed key.
|
|
|
|
Obviously this is quicker when there are fewer collisions, so hashing will
|
|
|
|
become inefficient if the number of items to be stored greatly exceeds the
|
|
|
|
size of the hash table.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{containers}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxList
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxHashTable : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Constructor. @a key_type is one of wxKEY_INTEGER, or wxKEY_STRING,
|
|
|
|
and indicates what sort of keying is required. @a size is optional.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-11-09 16:46:52 +00:00
|
|
|
wxHashTable(wxKeyType key_type = wxKEY_INTEGER, size_t size = 1000);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destroys the hash table.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxHashTable();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-11-03 14:37:14 +00:00
|
|
|
The counterpart of Next(). If the application wishes to iterate
|
|
|
|
through all the data in the hash table, it can call BeginFind() and
|
|
|
|
then loop on Next().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void BeginFind();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clears the hash table of all nodes (but as usual, doesn't delete user data).
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Deletes entry in hash table and returns the user's data (if found).
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxObject* Delete(long key);
|
|
|
|
wxObject* Delete(const wxString& key);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
2008-11-03 14:37:14 +00:00
|
|
|
If set to @true data stored in hash table will be deleted when hash table
|
|
|
|
object is destroyed.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void DeleteContents(bool flag);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-11-03 14:37:14 +00:00
|
|
|
Gets data from the hash table, using an integer or string key
|
|
|
|
(depending on which has table constructor was used).
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxObject* Get(long key);
|
|
|
|
wxObject* Get(const char* key);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of elements in the hash table.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
size_t GetCount() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Makes an integer key out of a string. An application may wish to make a key
|
|
|
|
explicitly (for instance when combining two data values to form a key).
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
static long MakeKey(const wxString& string);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
If the application wishes to iterate through all the data in the hash
|
2008-11-03 14:37:14 +00:00
|
|
|
table, it can call BeginFind() and then loop on Next(). This function
|
|
|
|
returns a @b wxHashTable::Node pointer (or @NULL if there are no more nodes).
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The return value is functionally equivalent to @b wxNode but might not be
|
|
|
|
implemented as a @b wxNode. The user will probably only wish to use the
|
2008-11-03 14:37:14 +00:00
|
|
|
wxNode::GetData() method to retrieve the data; the node may also be deleted.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxHashTable::Node* Next();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Inserts data into the hash table, using an integer or string key (depending on
|
2008-11-03 14:37:14 +00:00
|
|
|
which has table constructor was used).
|
|
|
|
The key string is copied and stored by the hash table implementation.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void Put(long key, wxObject* object);
|
|
|
|
void Put(const char* key, wxObject* object);
|
2008-03-08 13:52:38 +00:00
|
|
|
//@}
|
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|