prg_bin_hash_table_item_insert()
Abstract
Inserts a new value into a hash table.
Syntax
prg_bin_hash_table_item_insert (hash_ptr, key, value_ptr, old_value_pptr)
| Argument | Type | Description |
|---|---|---|
hash_ptr |
PrgT_Bin_Hash_Table * |
Hash table of interest. |
key |
const void * |
Key associated with the value to be inserted into the table. |
value_ptr |
void * |
Value to be inserted into the table. |
old_value_pptr |
void ** |
Area to hold a pointer to the previous value for key, if any; PRGC_NIL otherwise. |
Return Type
void
No return value.
Header
prg_bin_hash.h
Details
This function uses key to determine the location at which to insert value_ptr. If the hash table already contains a value for this key, the previous pointer is placed in old_value_pptr and removed from the hash table.
To guard against cases of duplicate keys, your code should check to see if old_value_pptr is PRGC_NIL. If not, the key was used previously and you must save the previous value somehow. One way is to use the chaining method, in which the hash table entry for duplicate keys is a list of values. To use the chaining method:
- Combine the cell’s previous value (from
old_value_pptr) and the new value (value_ptr) in a list. - Call
prg_bin_hash_table_item_insert()again to store this new list of values at the key position.
WARNING: This function is MT unsafe, as described in “Multi-Threading Safety“ on page 11. Access to shared hash tables must be externally serialized.