RWTPtrHashSet(3C++) RWTPtrHashSet(3C++)
Name
RWTPtrHashSet<T> - Rogue Wave library class
Synopsis
#include <rw/tphset.h>
unsigned hashFun(const T&);
Please Note!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.
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&)).
Persistence
None
Example
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;
}
Page 1
RWTPtrHashSet(3C++) RWTPtrHashSet(3C++)
Program output:
3
Public Constructor
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().
Public Member Functions
RWTPtrHashSet<T>&
Union(const RWTPtrHashSet<T>& h);
Computes the union of self and h, modifying self and returning self.
RWTPtrHashSet<T>&
difference(const RWTPtrHashSet<T>& h);
Computes the disjunction of self and h, modifying self and returning
self.
RWTPtrHashSet<T>&
intersection(const RWTPtrHashSet<T>& h);
Computes the intersection of self and h, modifying self and returning
self.
RWTPtrHashSet<T>&
symmetricDifference(const RWTPtrHashSet<T>& h);
Computes the symmetric difference between self and h, modifying self and
returning self.
RWBoolean
isSubsetOf(const RWTPtrHashSet<T>& h) const;
Returns TRUE if self is a subset of h.
Page 2
RWTPtrHashSet(3C++) RWTPtrHashSet(3C++)
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.
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>.
RWBoolean
contains(const T* a) const;
Inherited from class RWTPtrHashTable<T>.
size_t
entries() const;
Inherited from class RWTPtrHashTable<T>.
T*
find(const T* target) const;
Page 3
RWTPtrHashSet(3C++) RWTPtrHashSet(3C++)
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.
RWBoolean
isEmpty() const;
Inherited from class RWTPtrHashTable<T>.
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>.
Page 4