chtbl_init
int chtbl_init(CHTbl *htbl
, intbuckets
, int (*h
)(const void *key
), int (*match
)(const void *key1
, const void *key2
), void (*destroy
)(void *data
));
Initializes the chained hash table specified by
htbl
. This operation must be called for
a chained hash table before the hash table can be used with any
other operation. The number of buckets allocated in the hash table
is specified by buckets
. The function pointer h
specifies a user-defined hash function for hashing keys. The
function pointer match
specifies a
user-defined function to determine whether two keys match. It
should return 1 if key1
is equal to
key2
, and otherwise. The
destroy
argument provides a way to free
dynamically allocated data when chtbl_destroy
is called. For example, if the hash table contains data
dynamically allocated using malloc,
destroy
should be set to
free to free the data as the hash table is
destroyed. For structured data containing several dynamically
allocated members, destroy
should be
set to a user-defined function that calls
free for each dynamically allocated member as
well as for the structure itself. For a hash table containing data
that should not be freed, destroy
should be set to NULL.