casa
$Rev:20696$
|
Hash function with state
#include <HashMap.h>
Public Member Functions | |
virtual uInt | hash (const key &)=0 |
This function maps elements of key type to any integer. | |
virtual HashClass< key > * | clone () const =0 |
This function is used to make a deep copy. | |
HashClass () | |
virtual | ~HashClass () |
Hash function with state
Public interface
This is basically a way of specifying a hash function, but it is implemented as a class. Thus it is called HashClass, similar to "hash function".
This class is used to specify a hash function. Sometimes a hash function may require state, it may be useful to create a hierarchy of hash functions, or it may be useful to create a class which provides for hashing as well as other functionality. This class can be used as a base class for any of these purposed. This class is intended for parameterization of HashMap .
The hash function maps the key type to any integer. This integer is then used by HashMap to select a bucket in the hash table.
If one wished to make a HashClass for integers, something like the following might be done:
class IntHash : public HashClass<Int> { public: uInt hash(const Int &v) const { return (uInt) v; } uInt hash(const Int &v) { return (uInt) v; } HashClass<Int> *clone() const { return new IntHash; } IntHash() : HashClass<Int>() { } };
There may be occasions when it is more convenient to use a class instead of a single function. This base class provides a starting point plus, and HashMap<k,v>
has the necessary hooks to make use of classes derived from this class.
casa::HashClass< key >::HashClass | ( | ) |
virtual casa::HashClass< key >::~HashClass | ( | ) | [virtual] |
virtual HashClass<key>* casa::HashClass< key >::clone | ( | ) | const [pure virtual] |
This function is used to make a deep copy.
This means that the copy, which this function returns, contains all derived information.
virtual uInt casa::HashClass< key >::hash | ( | const key & | ) | [pure virtual] |
This function maps elements of key
type to any integer.
This integer is then used by HashMap to select a bucket in the hash table.