Tools.h++ Class Reference

Table Of Contents
Parameters K and V represent the type of the key and the type of the value, respectively, to be inserted
into the table. These can be either classes or fundamental types. Class K must have
well-defined equality semantics (K::operator==(const K&)).
Class V can be of any type.
A user-supplied hashing function for type K must be supplied to the constructor when creating a new
table. If K is a Rogue Wave class, then this requirement is usually trivial because most Rogue Wave
objects know how to return a hashing value. In fact, classes RWCString, RWDate, RWTime, and
RWWString contain static member functions called hash that can be supplied to the constructor as is.
The function must have prototype:
unsigned hFun(const K& a);
and should return a suitable hash value for the object a.
To find a value, the key is first hashed to determine in which bucket the key and value can be found.
The bucket is then searched for an object that is equal (as determined by the equality operator) to the
key.
The initial number of buckets in the table is set by the constructor. There is a default value. If the
number of (key/value) pairs in the collection greatly exceeds the number of buckets then efficiency will
sag because each bucket must be searched linearly. The number of buckets can be changed by calling
member function resize(). This is relatively expensive because all of the keys must be rehashed.
If you wish for this to be done automatically, then you can subclass from this class and implement your
own special insert() and remove() functions which perform a resize() as necessary.
Persistence
None
Example
#include <rw/tphdict.h>
#include <rw/cstring.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
main() {
RWTPtrHashDictionary<RWCString, RWDate>
birthdays(RWCString::hash);
birthdays.insertKeyAndValue
(new RWCString("John"),
new RWDate(12, "April", 1975)
);
birthdays.insertKeyAndValue
(new RWCString("Ivan"),
new RWDate(2, "Nov", 1980)
);