RWTPtrHashSet<T>RWTPtrHashTable<T>
#include <rw/tphset.h> unsigned hashFun(const T&); RWTPtrHashSet(hashFun) set;
If you do not have the Standard C++ Library, use the interface described here. Otherwise, use the interface to RWTPtrHashSet described in the Class Reference.
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&)).
None
This examples exercises a set of RWCStrings.
#include <rw/tphset.h> #include <rw/cstring.h> #include <rw/rstream.h> main() { RWTPtrHashSet<RWCString> set(RWCString::hash); set.insert(new RWCString("one")); set.insert(new RWCString("two")); set.insert(new RWCString("three")); set.insert(new RWCString("one")); cout << set.entries() << endl; // Prints "3" set.clearAndDestroy(); return 0; }
Program output:
3
RWTPtrHashSet<T>(unsigned (*hashFun)(const T&), size_t buckets = RWDEFAULT_CAPACITY);
Constructs an empty hashing set. The first argument is a pointer to a user-defined hashing function for items of type T. The table will initally have buckets buckets although this can be changed with member function resize().
RWBoolean operator!=(const RWTPtrHashSet<T>& h) const;
Returns FALSE if self and h are identical.
void apply(void (*applyFun)(T*, void*), void* d);
Inherited from class RWTPtrHashTable<T>.
void clear();
Inherited from class RWTPtrHashTable<T>.
void clearAndDestroy();
Inherited from class RWTPtrHashTable<T>. Do not use this method if multiple pointers to the same object are stored.
RWBoolean contains(const T* a) const;
Inherited from class RWTPtrHashTable<T>.
RWTPtrHashSet<T>& difference(const RWTPtrHashSet<T>& h);
Computes the disjunction of self and h, modifying self and returning self.
size_t entries() const;
Inherited from class RWTPtrHashTable<T>.
T* find(const T* target) const;
Inherited from class RWTPtrHashTable<T>.
void insert(T* a);
Redefined from class RWTPtrHashTable<T> to allow an object of a given value to be inserted only once.
RWTPtrHashSet<T>& intersection(const RWTPtrHashSet<T>& h);
Computes the intersection of self and h, modifying self and returning self.
RWBoolean isEmpty() const;
Inherited from class RWTPtrHashTable<T>.
RWBoolean isSubsetOf(const RWTPtrHashSet<T>& h) const;
Returns TRUE if self is a subset of h.
RWBoolean isProperSubsetOf(const RWTPtrHashSet<T>& h) const;
Returns TRUE if self is a proper subset of h.
RWBoolean isEquivalent(const RWTPtrHashSet<T>& h) const;
Returns TRUE if self and h are identical.
size_t occurrencesOf(const T* a) const;
Inherited from class RWTPtrHashTable<T>.
T* remove(const T* a);
Inherited from class RWTPtrHashTable<T>.
size_t removeAll(const T* a);
Inherited from class RWTPtrHashTable<T>.
void resize(size_t N);
Inherited from class RWTPtrHashTable<T>.
RWTPtrHashSet<T>& symmetricDifference(const RWTPtrHashSet<T>& h);
Computes the symmetric difference between self and h, modifying self and returning self.
RWTPtrHashSet<T>& Union(const RWTPtrHashSet<T>& h);
Computes the union of self and h, modifying self and returning self.