Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
This section describes an implementation of a scatter table using open addressing with linear probing. Program introduces the OpenScatterTable class. The OpenScatterTable class extends the AbstractHashTable class introduced in Program . The scatter table is implemented as an array of elements of the nested struct Entry. Each Entry instance has two fields--obj and state. The former is refers to a ComparableObject. The latter is an EntryState enum the value of which is either EMPTY, OCCUPIED or DELETED.
Program: OpenScatterTable fields, OpenScatterTable.EntryState enum, and OpenScatterTable.Entry struct.
Initially, all entries are empty. When an object recorded in an entry, the state of that entry is changed to OCCUPIED. The purpose of the third state, DELETED, will be discussed in conjunction with the Withdraw method below.