next up previous contents index
Next: 4.10.4 mb Up: 4.10 Classes Previous: 4.10.2 cnd   Contents   Index

Subsections


4.10.3 dch

The dch class implements dynamic chained hashing. The dch class is a wrapper around the ch class that enforces fullness/emptiness constraints and rebuilds the hash table when necessary. Other than this added functionality, the dch class behaves almost exactly like the ch class. See the ch class documentation for additional information.

4.10.3.1 API

dch_new(cw_dch_t *a_dch, cw_opaque_alloc_t *a_alloc, cw_opaque_dealloc_t *a_dealloc, void *a_arg, cw_uint32_t a_base_table, cw_uint32_t a_base_grow, cw_uint32_t a_base_shrink, cw_ch_hash_t *a_hash, cw_ch_key_comp_t *a_key_comp):

Input(s):
a_dch:
Pointer to space for a dch, or NULL.
a_alloc:
Pointer to an allocation function to use internally.
a_dealloc:
Pointer to a deallocation function to use internally.
a_arg:
Opaque pointer to pass to a_alloc() and a_dealloc().
a_base_table:
Number of slots in the initial hash table.
a_base_grow:
Maximum number of items to allow in a_dch before doubling the hash table size. The same proportions (in relation to a_base_table) are used to decide when to double the table additional times.
a_base_shrink:
Minimum proportional (with respect to a_base_table) emptiness to allow in the hash table before cutting the hash table size in half.
a_hash:
Pointer to a hashing function.
a_key_comp:
Pointer to a key comparison function.
Output(s):
retval:
Pointer to a dch.
Exception(s):
CW_ONYXX_OOM.
Description:
Constructor.
void dch_delete(cw_dch_t *a_dch):

Input(s):
a_dch:
Pointer to a dch.
Output(s):
None.
Exception(s):
None.
Description:
Destructor.
cw_uint32_t dch_count(cw_dch_t *a_dch):

Input(s):
a_dch:
Pointer to a dch.
Output(s):
retval:
Number of items in a_dch.
Exception(s):
None.
Description:
Return the number of items in a_dch.
void dch_insert(cw_dch_t *a_dch, const void *a_key, const void *a_data, cw_chi_t *a_chi):

Input(s):
a_dch:
Pointer to a dch.
a_key:
Pointer to a key.
a_data:
Pointer to data associated with a_key.
a_chi:
Pointer to space for a chi, or NULL.
Output(s):
None.
Exception(s):
CW_ONYXX_OOM.
Description:
Insert a_data into a_dch, using key a_key. Use a_chi for the internal chi container if non-NULL.
cw_bool_t dch_remove(cw_dch_t *a_dch, const void *a_search_key, void **r_key, void **r_data, cw_chi_t **r_chi):

Input(s):
a_dch:
Pointer to a dch.
a_search_key:
Pointer to the key to search with.
r_key:
Pointer to a key pointer, or NULL.
r_data:
Pointer to a data pointer, or NULL.
r_chi:
Pointer to a chi pointer, or NULL.
Output(s):
retval:
FALSE:
Success.
TRUE:
Item with key a_search_key not found.
*r_key:
If (r_key != NULL) and (retval == FALSE), pointer to a key. Otherwise, undefined.
*r_data:
If (r_data != NULL) and (retval == FALSE), pointer to data. Otherwise, undefined.
*r_chi:
If (r_chi != NULL) and (retval == FALSE), pointer to space for a chi, or NULL. Otherwise, undefined.
Exception(s):
None.
Description:
Remove the item from a_dch that was most recently inserted with key a_search_key. If successful, set *r_key and *r_data to point to the key, data, and externally allocated chi, respectively.
cw_bool_t dch_search(cw_dch_t *a_dch, const void *a_key, void **r_data):

Input(s):
a_dch:
Pointer to a dch.
a_key:
Pointer to a key.
r_data:
Pointer to a data pointer, or NULL.
Output(s):
retval:
FALSE:
Success.
TRUE:
Item with key a_key not found in a_dch.
*r_data:
If (r_data != NULL) and (retval == FALSE), pointer to data.
Exception(s):
None.
Description:
Search for the most recently inserted item with key a_key. If found, *r_data to point to the associated data.
cw_bool_t dch_get_iterate(cw_dch_t *a_dch, void **r_key, void **r_data):

Input(s):
a_dch:
Pointer to a dch.
r_key:
Pointer to a key pointer, or NULL.
r_data:
Pointer to a data pointer, or NULL.
Output(s):
retval:
FALSE:
Success.
TRUE:
a_dch is empty.
*r_key:
If (r_key != NULL) and (retval == FALSE), pointer to a key. Otherwise, undefined.
*r_data:
If (r_data != NULL) and (retval == FALSE), pointer to data. Otherwise, undefined.
Exception(s):
None.
Description:
Set *r_key and *r_data to point to the oldest item in a_dch. Promote the item so that it is the newest item in a_dch.
cw_bool_t dch_remove_iterate(cw_dch_t *a_dch, void **r_key, void **r_data, cw_chi_t **r_chi):

Input(s):
a_dch:
Pointer to a dch.
r_key:
Pointer to a key pointer, or NULL.
r_data:
Pointer to a data pointer, or NULL.
r_chi:
Pointer to a chi pointer, or NULL.
Output(s):
retval:
FALSE:
Success.
TRUE:
a_dch is empty.
*r_key:
If (r_key != NULL) and (retval == FALSE), pointer to a key. Otherwise, undefined.
*r_data:
If (r_data != NULL) and (retval == FALSE), pointer to data. Otherwise, undefined.
*r_chi:
If (r_chi != NULL) and (retval == FALSE), pointer to a chi, or NULL. Otherwise, undefined.
Exception(s):
None.
Description:
Set *r_key and *r_data to point to the oldest item in a_dch, set *r_chi to point to the item's container, if externally allocated, and remove the item from a_dch.


next up previous contents index
Next: 4.10.4 mb Up: 4.10 Classes Previous: 4.10.2 cnd   Contents   Index
Jason Evans 2003-01-31