Manages hash tables.
Standard C Library (libc.a)
#include <search.h>
ENTRY *hsearch ( Item, Action)
ENTRY Item;
Action Action;
int hcreate ( NumberOfElements)
size_t NumberOfElements;
void hdestroy ( )
The hsearch subroutine searches a hash table. It returns a pointer into a hash table that indicates the location of the given item. The hsearch subroutine uses open addressing with a multiplicative hash function.
The hcreate subroutine allocates sufficient space for the table. You must call the hcreate subroutine before calling the hsearch subroutine. The NumberOfElements parameter is an estimate of the maximum number of entries that the table will contain. This number may be adjusted upward by the algorithm in order to obtain certain mathematically favorable circumstances.
The hdestroy subroutine deletes the hash table. This action allows you to start a new hash table since only one table can be active at a time. After the call to the hdestroy subroutine, the data can no longer be considered accessible.
Item | Description |
---|---|
Item | Identifies a structure of the type ENTRY as defined
in the search.h file. It contains two pointers:
|
Action | Specifies the value of the Action enumeration parameter
that indicates what is to be done with an entry if it cannot be found
in the table. Values are:
|
NumberOfElements | Provides an estimate of the maximum number of entries that the table contains. Under some circumstances, the hcreate subroutine may actually make the table larger than specified. |
The hcreate subroutine returns a value of 0 if it cannot allocate sufficient space for the table.