Click on the banner to return to the Class Reference home page.
Return to the Appendix home page.

©Copyright 1996 Rogue Wave Software

RWTPtrHashSet<T>

Alternate template: Standard C++ Library not required


RWTPtrHashSet<T>RWTPtrHashTable<T>

Synopsis

#include <rw/tphset.h>
unsigned hashFun(const T&);
RWTPtrHashSet(hashFun) set;

Please Note!


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:

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;
}
 

Program output:

3

Public Constructor

RWTPtrHashSet<T>(unsigned (*hashFun)(const T&),
                 size_t buckets = RWDEFAULT_CAPACITY);

Public Member Functions

RWTPtrHashSet<T>&
Union(const RWTPtrHashSet<T>& h);
RWTPtrHashSet<T>&
difference(const RWTPtrHashSet<T>& h);
RWTPtrHashSet<T>&
intersection(const RWTPtrHashSet<T>& h);
RWTPtrHashSet<T>&
symmetricDifference(const RWTPtrHashSet<T>& h);
RWBoolean
isSubsetOf(const RWTPtrHashSet<T>& h) const;
RWBoolean
isProperSubsetOf(const RWTPtrHashSet<T>& h) const;
RWBoolean
isEquivalent(const RWTPtrHashSet<T>& h) const;
RWBoolean
operator!=(const RWTPtrHashSet<T>& h) const;
void
apply(void (*applyFun)(T*, void*), void* d);
void
clear();
void
clearAndDestroy();
RWBoolean
contains(const T* a) const;
size_t
entries() const;
T*
find(const T* target) const;
void
insert(T* a);
RWBoolean
isEmpty() const;
size_t
occurrencesOf(const T* a) const;
T*
remove(const T* a);
size_t
removeAll(const T* a);
void
resize(size_t N);