Name

ohtbl_init

Synopsis

int ohtbl_init(OHTbl *htbl, int positions, int (*h1)(const void *key) 
   int (*h2)(const void *key), int (*match)(const void *key1 
   const void *key2), void (*destroy)(void *data));

Return Value

0 if initializing the hash table is successful, or -1 otherwise.

Description

Initializes the open-addressed hash table specified by htbl. This operation must be called for an open-addressed hash table before the hash table can be used with any other operation. The number of positions to be allocated in the hash table is specified by positions. The function pointers h1 and h2 specify user-defined auxiliary hash functions for double hashing. The function pointer match specifies a user-defined function to determine if two keys match. It should perform in a manner similar to that described for chtbl_init. The destroy argument provides a way to free dynamically allocated data when ohtbl_destroy is called. It works in a manner similar to that described for chtbl_destroy. For an open-addressed hash table containing data that should not be freed, destroy should be set to NULL.

Complexity

O (m), where m is the number of positions in the hash table.

Get Mastering Algorithms with C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.