.\" This is a wxWidgets manpage page generated from the XML docs .TH wxHashSet 3wx 2005-02-15 "wxWidgets" "wxWidgets class documentation" .SH NAME wxHashSet \- A simple hash set implementation .SH DESCRIPTION This is a simple, type-safe, and reasonably efficient hash set class, whose interface is a subset of the interface of STL containers. In particular, the interface is modeled after std::set, and the various, non standard, std::hash_map. .SH "PARENTS" .SH "INCLUDE FILES" wx/hashset.h .SH MEMBERS .SS wxHashSet (size_type size = 10) The size parameter is just a hint, the table will resize automatically to preserve performance. .SS wxHashSet (const wxHashSet& set) Copy constructor. .SS const_iterator begin () .SS iterator begin () Returns an iterator pointing at the first element of the hash set. Please remember that hash sets do not guarantee ordering. .SS void clear () Removes all elements from the hash set. .SS size_type count (const key_type& key) Counts the number of elements with the given key present in the set. This function returns only 0 or 1. .SS bool empty () Returns true if the hash set does not contain any elements, false otherwise. .SS const_iterator end () .SS iterator 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. .SS 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). .SS void erase (iterator it) .SS void 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. .SS iterator find (const key_type& key) .SS const_iterator find (const key_type& key) 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. hashset.find( non_existent_key ) == hashset.end()). .SS Insert_Result insert (const value_type& v) Inserts the given value in the hash set. The return value is equivalent to a std::pair ; the iterator points to the inserted element, the boolean value is true if v was actually inserted. .SS size_type size () Returns the number of elements in the set. .SH EXAMPLE class MyClass { /* ... */ }; // same, with MyClass* keys (only uses pointer equality!) WX_DECLARE_HASH_SET( MyClass*, wxPointerHash, wxPointerEqual, MySet1 ); // same, with int keys WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual, MySet2 ); // declare a hash set with string keys WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual, MySet3 ); MySet1 h1; MySet2 h1; MySet3 h3; // store and retrieve values h1.insert( new MyClass( 1 ) ); h3.insert( "foo" ); h3.insert( "bar" ); h3.insert( "baz" ); int size = h3.size(); // now is three bool has_foo = h3.find( "foo" ) != h3.end(); h3.insert( "bar" ); // still has size three // iterate over all the elements in the class MySet3::iterator it; for( it = h3.begin(); it != h3.end(); ++it ) { wxString key = *it; // do something useful with key } Declaring new hash set types WX_DECLARE_HASH_SET( KEY_T, // type of the keys HASH_T, // hasher KEY_EQ_T, // key equality predicate CLASSNAME); // name of the class 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: WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual, MySet ); // using an user-defined class for keys class MyKey { /* ... */ }; // hashing function class MyKeyHash { public: MyKeyHash() { } unsigned long operator()( const MyKey& k ) const { /* compute the hash */ } MyKeyHash& operator=(const MyKeyHash&) { return *this; } }; // comparison operator class MyKeyEqual { public: MyKeyEqual() { } bool operator()( const MyKey& a, const MyKey& b ) const { /* compare for equality */ } MyKeyEqual& operator=(const MyKeyEqual&) { return *this; } }; WX_DECLARE_HASH_SET( MyKey, // type of the keys MyKeyHash, // hasher MyKeyEqual, // key equality predicate CLASSNAME); // name of the class .SH "SEE ALSO" .SH "AUTHORS" Documentation content by Julian Smart, Robert Roebling, Vadim Zeitlin, Robin Dunn, et al Conversion to manpage format by Arnout Engelen (http://bzzt.net), bugreports welcome.