prg_string_hash_table_create()
Abstract
Creates a new hash table.
Syntax
prg_string_hash_table_create (table_size, max_chars)
| Argument | Type | Description |
|---|---|---|
table_size |
int |
The number of cells the hash table should contain. |
max_chars |
int |
The maximum number of characters in the key string that should be used when computing the hash value. |
Return Type
PrgT_String_Hash_Table *
Pointer to the new hash table.
Header
prg_string_hash_funcs.h
Details
This function creates a new hash table owned by the caller. The number of cells in the table will not change as new (key,value) pairs are added.
WARNING: This function is MT unsafe, as described in “Multi-Threading Safety“ on page 11. Access to shared hash tables must be externally serialized.
The value of table_size relative to the number of (key,value) pairs inserted into the table will help determine the average “lookup speed” of keys. Generally, table_size should be on the order of the maximum number of items expected in the hash table.
- A smaller size means more collisions and thus longer search times for a specified key.
- A larger size means fewer collisions and reduced search time, but increased memory requirements.
For this data structure, only strings can be used as keys. Select a value for max_chars that will most likely capture the unique characters of the anticipated strings. This value can affect the efficiency of hashing:
- A larger value means the hash function computation takes longer.
- A smaller value can mean many strings will hash to the same cell, resulting in a large number of items per cell.