HashTable

Summary
Default number of buckets for a hash table.
Defines the interface to a hash function.
Hash table implementation of the shared string manager.
Construct a new hash table implementation of the shared string manager.
Resize the array of buckets, and rehash all table contents into the new buckets.

Constants

HASH_TABLE_SIZE

Default number of buckets for a hash table.

Types

HashFunction

Defines the interface to a hash function.  Takes a const char * as an argument and returns a size_t.

typedef size_t HashFunction (const char *);

Here is a simple, but very inefficient, hash function (from SMAUG);

size_t SmaugHash(const char * str)
{
return strlen(str);
}

This is however a lousy hash function, since it distributes strings extremely poorly.  See the sample hash table manager for a better hash function.

HashTable

Hash table implementation of the shared string manager.

TODO: Finish this documentation

Summary
Construct a new hash table implementation of the shared string manager.
Resize the array of buckets, and rehash all table contents into the new buckets.

Functions

Constructor

Construct a new hash table implementation of the shared string manager.  Note that you need to pass in a hash function: see the HashFunction typedef.

Parameters

fPointer to the hash function to use.

rehash

void rehash(size_t newSize)

Resize the array of buckets, and rehash all table contents into the new buckets.  Use this if you have too many elements per bucket and don’t mind spending more memory on buckets.  Note that this will only be useful if your hash function is good enough to distribute over all the buckets.

Parameters

newSizeThe size to which to resize the number of buckets.
void rehash(size_t newSize)
Resize the array of buckets, and rehash all table contents into the new buckets.
Defines the interface to a hash function.