| Version: 3.3.1

Public Member Functions | Static Public Member Functions | List of all members
wxHashTable Class Reference
Class List by Category » Containers

`#include <wx/hash.h>`

Inheritance diagram for wxHashTable:
[legend]

## Detailed Description

Deprecated:
  Please note that this class is retained for backward compatibility reasons; you should use wxHashMap.

This class provides hash table functionality for wxWidgets, and for an application if it wishes. Data can be hashed on an integer or string key.

Example:

wxHashTable table(wxKEY_STRING);
wxPoint *point = new wxPoint(100, 200);
table.Put("point 1", point);
....
wxPoint *found_point = (wxPoint *)table.Get("point 1");
wxHashTable
Definition: hash.h:50
wxPoint
A wxPoint is a useful data structure for graphics operations.
Definition: gdicmn.h:686

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 nullptr, 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.

##

Library: wxBase
Category: Containers

See also
  wxList

## Public Member Functions
| wxHashTable (wxKeyType key_type=wxKEY_INTEGER, size_t size=1000)
| Constructor. More...
virtual | ~wxHashTable ()
| Destroys the hash table. More...
void | BeginFind ()
| The counterpart of Next(). More...
void | Clear ()
| Clears the hash table of all nodes (but as usual, doesn't delete user data). More...
void | DeleteContents (bool flag)
| If set to true data stored in hash table will be deleted when hash table object is destroyed. More...
size_t | GetCount () const
| Returns the number of elements in the hash table. More...
wxHashTable::Node * | Next ()
| If the application wishes to iterate through all the data in the hash table, it can call BeginFind() and then loop on Next(). More...
wxObject * | Delete (long key)
| Deletes entry in hash table and returns the user's data (if found). More...
wxObject * | Delete (const wxString &key)
| Deletes entry in hash table and returns the user's data (if found). More...
wxObject * | Get (long key)
| Gets data from the hash table, using an integer or string key (depending on which has table constructor was used). More...
wxObject * | Get (const char *key)
| Gets data from the hash table, using an integer or string key (depending on which has table constructor was used). More...
void | Put (long key, wxObject *object)
| Inserts data into the hash table, using an integer or string key (depending on which has table constructor was used). More...
void | Put (const char *key, wxObject *object)
| Inserts data into the hash table, using an integer or string key (depending on which has table constructor was used). More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to nullptr the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=nullptr, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Static Public Member Functions
static long | MakeKey (const wxString &string)
| Makes an integer key out of a string. More...

## Additional Inherited Members
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ wxHashTable()

wxHashTable::wxHashTable | ( | wxKeyType | key_type = `wxKEY_INTEGER`,
|  | size_t | size = `1000`
| ) |  |

Constructor.

key_type is one of wxKEY_INTEGER, or wxKEY_STRING, and indicates what sort of keying is required. size is optional.

## ◆ ~wxHashTable()

virtual wxHashTable::~wxHashTable | ( |  | ) |
| virtual

Destroys the hash table.

## Member Function Documentation

## ◆ BeginFind()

void wxHashTable::BeginFind | ( |  | ) |

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().

## ◆ Clear()

void wxHashTable::Clear | ( |  | ) |

Clears the hash table of all nodes (but as usual, doesn't delete user data).

## ◆ Delete() [1/2]

wxObject* wxHashTable::Delete | ( | const wxString & | key | ) |

Deletes entry in hash table and returns the user's data (if found).

## ◆ Delete() [2/2]

wxObject* wxHashTable::Delete | ( | long | key | ) |

Deletes entry in hash table and returns the user's data (if found).

## ◆ DeleteContents()

void wxHashTable::DeleteContents | ( | bool | flag | ) |

If set to true data stored in hash table will be deleted when hash table object is destroyed.

## ◆ Get() [1/2]

wxObject* wxHashTable::Get | ( | const char * | key | ) |

Gets data from the hash table, using an integer or string key (depending on which has table constructor was used).

## ◆ Get() [2/2]

wxObject* wxHashTable::Get | ( | long | key | ) |

Gets data from the hash table, using an integer or string key (depending on which has table constructor was used).

## ◆ GetCount()

size_t wxHashTable::GetCount | ( |  | ) | const

Returns the number of elements in the hash table.

## ◆ MakeKey()

static long wxHashTable::MakeKey | ( | const wxString & | string | ) |
| static

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).

## ◆ Next()

wxHashTable::Node* wxHashTable::Next | ( |  | ) |

If the application wishes to iterate through all the data in the hash table, it can call BeginFind() and then loop on Next().

This function returns a wxHashTable::Node pointer (or nullptr if there are no more nodes).

The return value is functionally equivalent to wxNode but might not be implemented as a wxNode. The user will probably only wish to use the wxNode::GetData() method to retrieve the data; the node may also be deleted.

## ◆ Put() [1/2]

void wxHashTable::Put | ( | const char * | key,
|  | wxObject * | object
| ) |  |

Inserts data into the hash table, using an integer or string key (depending on which has table constructor was used).

The key string is copied and stored by the hash table implementation.

## ◆ Put() [2/2]

void wxHashTable::Put | ( | long | key,
|  | wxObject * | object
| ) |  |

Inserts data into the hash table, using an integer or string key (depending on which has table constructor was used).

The key string is copied and stored by the hash table implementation.