#include <wx/hashset.h>
This is a simple, type-safe, and reasonably efficient hash set class, whose interface is a subset of the interface of STL containers.
The interface is similar to std::tr1::hash_set or std::set classes but notice that, unlike std::set, the contents of a hash set is not sorted.
Example:
The HASH_T and KEY_EQ_T are the types used for the hashing function and key comparison. wxWidgets provides three predefined hashing functions: wxIntegerHash for integer types ( int, long, short, and their unsigned counterparts ), wxStringHash for strings ( wxString, wxChar*, char* ), and wxPointerHash for any kind of pointer. Similarly three equality predicates: wxIntegerEqual, wxStringEqual, wxPointerEqual are provided. Using this you could declare a hash set using int values like this:
In the documentation below you should replace wxHashSet with the name you used in the class declaration.
An iterator is similar to a pointer, and so you can use the usual pointer operations: ++it ( and it++ ) to move to the next element, *it to access the element pointed to, *it to access the value of the element pointed to. Hash sets provide forward only iterators, this means that you can't use –it, it + 3, it1 - it2.
Public Member Functions | |
wxHashSet (size_type size=10) | |
The size parameter is just a hint, the table will resize automatically to preserve performance. More... | |
wxHashSet (const wxHashSet &set) | |
Copy constructor. More... | |
void | clear () |
Removes all elements from the hash set. More... | |
size_type | count (const key_type &key) const |
Counts the number of elements with the given key present in the set. More... | |
bool | empty () const |
Returns true if the hash set does not contain any elements, false otherwise. More... | |
size_type | erase (const key_type &key) |
Erases the element with the given key, and returns the number of elements erased (either 0 or 1). More... | |
Insert_Result | insert (const value_type &v) |
Inserts the given value in the hash set. More... | |
size_type | size () const |
Returns the number of elements in the set. More... | |
const_iterator | begin () const |
Returns an iterator pointing at the first element of the hash set. More... | |
iterator | begin () |
Returns an iterator pointing at the first element of the hash set. More... | |
const_iterator | end () const |
Returns an iterator pointing at the one-after-the-last element of the hash set. More... | |
iterator | end () |
Returns an iterator pointing at the one-after-the-last element of the hash set. More... | |
void | erase (iterator it) |
Erases the element pointed to by the iterator. More... | |
void | erase (const_iterator it) |
Erases the element pointed to by the iterator. More... | |
iterator | find (const key_type &key) const |
If an element with the given key is present, the functions returns an iterator pointing at that element, otherwise an invalid iterator is returned. More... | |
const_iterator | find (const key_type &key) const |
If an element with the given key is present, the functions returns an iterator pointing at that element, otherwise an invalid iterator is returned. More... | |
wxHashSet::wxHashSet | ( | size_type | size = 10 | ) |
The size parameter is just a hint, the table will resize automatically to preserve performance.
wxHashSet::wxHashSet | ( | const wxHashSet & | set | ) |
Copy constructor.
const_iterator wxHashSet::begin | ( | ) | const |
Returns an iterator pointing at the first element of the hash set.
Please remember that hash sets do not guarantee ordering.
iterator wxHashSet::begin | ( | ) |
Returns an iterator pointing at the first element of the hash set.
Please remember that hash sets do not guarantee ordering.
void wxHashSet::clear | ( | ) |
Removes all elements from the hash set.
size_type wxHashSet::count | ( | const key_type & | key | ) | const |
Counts the number of elements with the given key present in the set.
This function returns only 0 or 1.
bool wxHashSet::empty | ( | ) | const |
Returns true if the hash set does not contain any elements, false otherwise.
const_iterator wxHashSet::end | ( | ) | const |
Returns an iterator pointing at the one-after-the-last element of the hash set.
Please remember that hash sets do not guarantee ordering.
iterator wxHashSet::end | ( | ) |
Returns an iterator pointing at the one-after-the-last element of the hash set.
Please remember that hash sets do not guarantee ordering.
size_type wxHashSet::erase | ( | const key_type & | key | ) |
Erases the element with the given key, and returns the number of elements erased (either 0 or 1).
void wxHashSet::erase | ( | iterator | it | ) |
Erases the element pointed to by the iterator.
After the deletion the iterator is no longer valid and must not be used.
void wxHashSet::erase | ( | const_iterator | it | ) |
Erases the element pointed to by the iterator.
After the deletion the iterator is no longer valid and must not be used.
iterator wxHashSet::find | ( | const key_type & | key | ) | const |
If an element with the given key is present, the functions returns an iterator pointing at that element, otherwise an invalid iterator is returned.
i.e.
const_iterator wxHashSet::find | ( | const key_type & | key | ) | const |
If an element with the given key is present, the functions returns an iterator pointing at that element, otherwise an invalid iterator is returned.
i.e.
Insert_Result wxHashSet::insert | ( | const value_type & | v | ) |
Inserts the given value in the hash set.
The return value is equivalent to a
The iterator points to the inserted element, the boolean value is true if v was actually inserted.
size_type wxHashSet::size | ( | ) | const |
Returns the number of elements in the set.