Tools.h++ Manual

22-38 104011 Tandem Computers Incorporated
22
RWTPtrHashSet<T>
RWTPtrHashSet<T>
|
RWTPtrHashTable<T>
Synopsis
#include <rw/tphset.h>
unsigned hashFun(const T&);
RWTPtrHashSet(hashFun) set;
Description
RWTPtrHashSet<T>
is a derived class of
RWTPtrHashTable<T>
where the
insert()
function has been overridden to accept only one item of a given
value. Hence, each item in the collection will have a unique value.
As with class
RWTPtrHashTable<T>
, you must supply a hashing function to
the constructor.
The class
T
must have:
well-defined equality semantics (
T::operator==(const T&)
).
Example This examples exercises a set of
RWCStrings
.
Code Example 22-3
#include <rw/tphset.h>
#include <rw/cstring.h>
#include <rw/rstream.h>
unsigned hashIt(const RWCString& str){ return str.hash(); }
main()
{
RWTPtrHashSet<RWCString> set(hashIt);
set.insert(new RWCString("one"));
set.insert(new RWCString("two"));
set.insert(new RWCString("three"));
set.insert(new RWCString("one"));