Hash Tables

Hash tables are lists that are indexed by an ASCII string.

A hash function computes the key index from the string to make random accesses reasonably efficient. They are much more efficient, for example, than a linear search over a SequentialList. Two of these classes are provided in the MLDesigner kernel. The first, HashTable, is generic, in that the table entries are of type Pointer, and thus can point to any user-defined data structure. The second, TextTable, is more specialized; the entries are strings. It is derived from HashTable.

HashTable

The HashTable class has a standard iterator called HashTableIter, where the next method and ++ operator return a pointer to class HashEntry. This class has a const char* key() method that returns the key for the entry, and a Pointer value() method that returns a pointer to the entry.

TextTable

The TextTable class has an iterator called TextTableIter, where the next method and ++ operator return a pointer to class TextEntry. This class inherits the const char* key() method from the HashEntry class which returns the key for the entry. But it implements its own value() method that returns a const char*.