Tools.h++ Manual

21-122 104011 Tandem Computers Incorporated
21
RWHashTable
RWHashTable
|
RWCollection
|
RWCollectable
Synopsis
#include <rw/hashtab.h>
RWHashTable h;
Description This class is a simple hash table for objects inheriting from
RWCollectable
. It
uses chaining (as implemented by class
RWSlistCollectables
) to resolve
hash collisions. Duplicate objects are allowed.
An object stored by
RWHashTable
must inherit from the abstract base class
RWCollectable
, with suitable definition for virtual functions
hash()
and
isEqual()
(see class
RWCollectable
).
To find an object that matches a key, the key's virtual function
hash()
is first
called to determine in which bucket the object occurs. The bucket is then
searched linearly by calling the virtual function
isEqual()
for each
candidate, with the key as the argument. The first object to return
TRUE
is the
returned object.
The initial number of buckets in the table is set by the constructor. There is a
default value. If the number of items 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 will require that all objects be rehashed.
The iterator for this class is
RWHashTableIterator
.