prg_mapping_create()
Abstract
Creates a one-to-one mapping between keys and values.
Syntax
prg_mapping_create (key_of_value_proc, lessthan_proc, destroy_proc)
| Argument | Type | Description |
|---|---|---|
key_of_value_proc |
PrgT_Mapping_Key_Of_Value_Proc |
Function used by the prg_mapping package to compute the key associated with a given value |
lessthan_proc |
PrgT_Mapping_Key_Lessthan_Proc |
Function used by the prg_mapping package to compare two keys to find out if one is less than the other or not. This can be PRGC_NIL, in which case the `<` operator is used on the key values. |
destroy_proc |
PrgT_Mapping_Value_Destroy_Proc |
Function used by the prg_mapping package to destroy a value stored in it. This can be PRGC_NIL, in which case values are not destroyed. |
Return Type
PrgT_Mapping_Handle
The created mapping (or PRGC_NIL if something prevented the creation)
Header
prg_mapping.h
Details
Used to create a mapping data structure that can be used to search a value or its key in O(log(n)) (where n is the number of stored elements).
Keys and values are represented by void * in this package.
The creation function takes three parameter functions to tailor its behavior to the specificity of the keys and values:
/* Given a value, returns the corresponding key */
void * PrgT_Mapping_Key_Of_Value_Proc (void * value);
/* return 1 if keya < keyb, 0 otherwise */
int PrgT_Mapping_Key_Lessthan_Proc (void * key_a, void * key_b);
/* destroy the provided value */
void PrgT_Mapping_Value_Destroy_Proc (void * value_ptr);