Go to the source code of this file.
Classes | |
struct | adt_Table_t |
Table container class. More... | |
Defines | |
#define | ADT_ERROR (-1) |
Typedefs | |
typedef adt_Table_t | adt_Table |
Table container class. | |
Functions | |
adt_Table * | adt_createTable (int size) |
Constructor. | |
void | adt_destroyTable (adt_Table *) |
Destructor. | |
int | adt_insertTable (adt_Table *, const char *key, int value) |
Insert (key , value ) pair into table. | |
int | adt_lookupTable (adt_Table *, const char *key) |
Lookup table entry value associated with given key. | |
int | adt_updateTable (adt_Table *, const char *key, int newvalue) |
Update value for table entry. | |
int | adt_deleteTable (adt_Table *, const char *key) |
Delete key and its associated value from table. | |
int | adt_initializeTable (adt_Table *, int size) |
Alternative constructor. | |
void | adt_cleanupTable (adt_Table *) |
Alternative destructor. | |
const char * | adt_getStatsTable (adt_Table *) |
Compute table statistics. |
adt_Table
class provides an association table, a mapping of keys to values (i.e. any key has exactly one value associated with it). The keys are nil-terminated strings and the values are nonnegative integers (most likely an array index). The adt_Table
supports fast
The integer value associated with a key is intended to be an array index (i.e. nonnegative). Otherwise, the value will conflict with the ADT_ERROR
(-1) return value indicating an error. The const
char
*
strings passed in as keys are aliased by the table, so they must persist at least as long as the table does. The easiest way is to use string literals as hash keys.
Errors are generally indicated by a return value of ADT_ERROR
, due either to failed memory allocation or inability to find a key in the table, depending on the function.
The hash table implementation was donated by John Stone, and the interface was subsequently modified by David Hardy.
|
Return value from failed function call. |
|
Table container class. Members should be treated as private. |
|
Alternative destructor.
Use to destroy a preallocated table object (i.e. one constructed using |
|
Constructor. Creates dynamically allocated table object.
size can avoid resizing, roughly twice the number of expected table entries.
|
|
Delete key and its associated value from table.
|
|
Destructor. Frees dynamically allocated table space and dynamically allocated table object. |
|
Compute table statistics.
|
|
Alternative constructor.
Use to construct a preallocated table object. See |
|
Insert (
key persists until after the table is destroyed. The associated value is probably an array index.
This routine does not update an existing value for
|
|
Lookup table entry value associated with given key.
|
|
Update value for table entry.
key , value ) association in place:
|