HP C/iX Library Reference Manual (30026-90004)
Chapter 5 207
HP C/iX Library Function Descriptions
hcreate
hcreate
Allocates sufficient space for a hash table used by the hsearch function.
Syntax
#include <search.h>
int hcreate (unsigned
nel
);
Parameters
nel
An estimate of the maximum number of elements that the table contains.
This number may be adjusted upward by the algorithm to obtain a
mathematically favorable table size.
Return Values
≠0 Successful. The space was allocated.
0 The space sufficient to contain the number of entries specified in
nel
was
not available. Therefore, no space was allocated.
Description
The hcreate function allocates space sufficient for a hash table that is to be searched by
the hsearch function. The size of the space is determined by the
nel
parameter. The hash
table itself is an array of pointers. The size of the data elements to be searched is not
relevant to determining the amount of memory to be allocated for the hash table.
Only one hash search table may be active at any given time.
The hcreate function must be called before hsearch() to allocate sufficient space for the
hash table.
NOTE
The hcreate function and the header file <search.h> are not part of ANSI C.
Using them may make your program less portable.
The hdestroy function may be used to deallocate the hash table when it is no longer
needed.
Examples
The following example reads in strings followed by two numbers and stores them in a hash
table, discarding duplicates. It then reads in strings and finds the matching entry in the
hash table and prints it out.
#include <stdio.h>
#include <search.h>
struct info { /* this is the info stored in the table */