Tools.h++ Manual

22-86 104011 Tandem Computers Incorporated
22
member function
resize()
. This is an expensive proposition because not
only must all the items be copied into the new buckets, but all of the keys must
be rehashed.
If you wish 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.
Example
Program output:
April 12, 1975
Public constructors
RWTValHashDictionary<K,V>(unsigned (*hashKey)(const K&),
size_t buckets = RWDEFAULT_CAPACITY);
Constructs a new hash dictionary. The first argument is a pointer to a user-
#include <rw/tvhdict.h>
#include <rw/cstring.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
unsigned hashString(const RWCString& str){return str.hash();}
main()
{
RWTValHashDictionary<RWCString, RWDate> birthdays(hashString);
birthdays.insertKeyAndValue("John", RWDate(12, "April", 1975));
birthdays.insertKeyAndValue("Ivan", RWDate(2, "Nov", 1980));
// Alternative syntax:
birthdays["Susan"] = RWDate(30, "June", 1955);
birthdays["Gene"] = RWDate(5, "Jan", 1981);
// Print a birthday:
cout << birthdays["John"] << endl;
return 0;
}