gdsl
1.6
|
Typedefs | |
typedef struct hash_table * | gdsl_hash_t |
GDSL hashtable type. | |
typedef const char *(* | gdsl_key_func_t )(void *VALUE) |
GDSL hashtable key function type. | |
typedef ulong(* | gdsl_hash_func_t )(const char *KEY) |
GDSL hashtable hash function type. | |
Functions | |
ulong | gdsl_hash (const char *KEY) |
Computes a hash value from a NULL terminated character string. | |
gdsl_hash_t | gdsl_hash_alloc (const char *NAME, gdsl_alloc_func_t ALLOC_F, gdsl_free_func_t FREE_F, gdsl_key_func_t KEY_F, gdsl_hash_func_t HASH_F, ushort INITIAL_ENTRIES_NB) |
Create a new hashtable. | |
void | gdsl_hash_free (gdsl_hash_t H) |
Destroy a hashtable. | |
void | gdsl_hash_flush (gdsl_hash_t H) |
Flush a hashtable. | |
const char * | gdsl_hash_get_name (const gdsl_hash_t H) |
Get the name of a hashtable. | |
ushort | gdsl_hash_get_entries_number (const gdsl_hash_t H) |
Get the number of entries of a hashtable. | |
ushort | gdsl_hash_get_lists_max_size (const gdsl_hash_t H) |
Get the max number of elements allowed in each entry of a hashtable. | |
ushort | gdsl_hash_get_longest_list_size (const gdsl_hash_t H) |
Get the number of elements of the longest list entry of a hashtable. | |
ulong | gdsl_hash_get_size (const gdsl_hash_t H) |
Get the size of a hashtable. | |
double | gdsl_hash_get_fill_factor (const gdsl_hash_t H) |
Get the fill factor of a hashtable. | |
gdsl_hash_t | gdsl_hash_set_name (gdsl_hash_t H, const char *NEW_NAME) |
Set the name of a hashtable. | |
gdsl_element_t | gdsl_hash_insert (gdsl_hash_t H, void *VALUE) |
Insert an element into a hashtable (PUSH). | |
gdsl_element_t | gdsl_hash_remove (gdsl_hash_t H, const char *KEY) |
Remove an element from a hashtable (POP). | |
gdsl_hash_t | gdsl_hash_delete (gdsl_hash_t H, const char *KEY) |
Delete an element from a hashtable. | |
gdsl_hash_t | gdsl_hash_modify (gdsl_hash_t H, ushort NEW_ENTRIES_NB, ushort NEW_LISTS_MAX_SIZE) |
Increase the dimensions of a hashtable. | |
gdsl_element_t | gdsl_hash_search (const gdsl_hash_t H, const char *KEY) |
Search for a particular element into a hashtable (GET). | |
gdsl_element_t | gdsl_hash_map (const gdsl_hash_t H, gdsl_map_func_t MAP_F, void *USER_DATA) |
Parse a hashtable. | |
void | gdsl_hash_write (const gdsl_hash_t H, gdsl_write_func_t WRITE_F, FILE *OUTPUT_FILE, void *USER_DATA) |
Write all the elements of a hashtable to a file. | |
void | gdsl_hash_write_xml (const gdsl_hash_t H, gdsl_write_func_t WRITE_F, FILE *OUTPUT_FILE, void *USER_DATA) |
Write the content of a hashtable to a file into XML. | |
void | gdsl_hash_dump (const gdsl_hash_t H, gdsl_write_func_t WRITE_F, FILE *OUTPUT_FILE, void *USER_DATA) |
Dump the internal structure of a hashtable to a file. |
typedef struct hash_table* gdsl_hash_t |
GDSL hashtable type.
This type is voluntary opaque. Variables of this kind could'nt be directly used, but by the functions of this module.
Definition at line 54 of file gdsl_hash.h.
typedef const char*(* gdsl_key_func_t)(void *VALUE) |
GDSL hashtable key function type.
VALUE | The value used to get the key from |
Definition at line 62 of file gdsl_hash.h.
typedef ulong(* gdsl_hash_func_t)(const char *KEY) |
GDSL hashtable hash function type.
KEY | the key used to compute the hash code. |
Definition at line 70 of file gdsl_hash.h.
Computes a hash value from a NULL terminated character string.
This function computes a hash value from the NULL terminated KEY string.
KEY | The NULL terminated string to compute the key from |
gdsl_hash_t gdsl_hash_alloc | ( | const char * | NAME, |
gdsl_alloc_func_t | ALLOC_F, | ||
gdsl_free_func_t | FREE_F, | ||
gdsl_key_func_t | KEY_F, | ||
gdsl_hash_func_t | HASH_F, | ||
ushort | INITIAL_ENTRIES_NB | ||
) |
Create a new hashtable.
Allocate a new hashtable data structure which name is set to a copy of NAME. The new hashtable will contain initially INITIAL_ENTRIES_NB lists. This value could be (only) increased with gdsl_hash_modify() function. Until this function is called, then all H's lists entries have no size limit. The function pointers ALLOC_F and FREE_F could be used to respectively, alloc and free elements in the hashtable. The KEY_F function must provide a unique key associated to its argument. The HASH_F function must compute a hash code from its argument. These pointers could be set to NULL to use the default ones:
NAME | The name of the new hashtable to create |
ALLOC_F | Function to alloc element when inserting it in the hashtable |
FREE_F | Function to free element when deleting it from the hashtable |
KEY_F | Function to get the key from an element |
HASH_F | Function used to compute the hash value. |
INITIAL_ENTRIES_NB | Initial number of entries of the hashtable |
void gdsl_hash_free | ( | gdsl_hash_t | H | ) |
Destroy a hashtable.
Deallocate all the elements of the hashtable H by calling H's FREE_F function passed to gdsl_hash_alloc(). The name of H is deallocated and H is deallocated itself too.
H | The hashtable to destroy |
void gdsl_hash_flush | ( | gdsl_hash_t | H | ) |
Flush a hashtable.
Deallocate all the elements of the hashtable H by calling H's FREE_F function passed to gdsl_hash_alloc(). H is not deallocated itself and H's name is not modified.
H | The hashtable to flush |
const char* gdsl_hash_get_name | ( | const gdsl_hash_t | H | ) |
Get the name of a hashtable.
H | The hashtable to get the name from |
ushort gdsl_hash_get_entries_number | ( | const gdsl_hash_t | H | ) |
Get the number of entries of a hashtable.
H | The hashtable to use. |
ushort gdsl_hash_get_lists_max_size | ( | const gdsl_hash_t | H | ) |
Get the max number of elements allowed in each entry of a hashtable.
H | The hashtable to use. |
ushort gdsl_hash_get_longest_list_size | ( | const gdsl_hash_t | H | ) |
Get the number of elements of the longest list entry of a hashtable.
H | The hashtable to use. |
ulong gdsl_hash_get_size | ( | const gdsl_hash_t | H | ) |
Get the size of a hashtable.
H | The hashtable to get the size from |
double gdsl_hash_get_fill_factor | ( | const gdsl_hash_t | H | ) |
Get the fill factor of a hashtable.
H | The hashtable to use |
gdsl_hash_t gdsl_hash_set_name | ( | gdsl_hash_t | H, |
const char * | NEW_NAME | ||
) |
Set the name of a hashtable.
Change the previous name of the hashtable H to a copy of NEW_NAME.
H | The hashtable to change the name |
NEW_NAME | The new name of H |
gdsl_element_t gdsl_hash_insert | ( | gdsl_hash_t | H, |
void * | VALUE | ||
) |
Insert an element into a hashtable (PUSH).
Allocate a new element E by calling H's ALLOC_F function on VALUE. The key K of the new element E is computed using KEY_F called on E. If the value of gdsl_hash_get_lists_max_size(H) is not reached, or if it is equal to zero, then the insertion is simple. Otherwise, H is re-organized as follow:
H | The hashtable to modify |
VALUE | The value used to make the new element to insert into H |
gdsl_element_t gdsl_hash_remove | ( | gdsl_hash_t | H, |
const char * | KEY | ||
) |
Remove an element from a hashtable (POP).
Search into the hashtable H for the first element E equal to KEY. If E is found, it is removed from H and then returned.
H | The hashtable to modify |
KEY | The key used to find the element to remove |
gdsl_hash_t gdsl_hash_delete | ( | gdsl_hash_t | H, |
const char * | KEY | ||
) |
Delete an element from a hashtable.
Remove from he hashtable H the first founded element E equal to KEY. If E is found, it is removed from H and E is deallocated using H's FREE_F function passed to gdsl_hash_alloc(), then H is returned.
H | The hashtable to modify |
KEY | The key used to find the element to remove |
gdsl_hash_t gdsl_hash_modify | ( | gdsl_hash_t | H, |
ushort | NEW_ENTRIES_NB, | ||
ushort | NEW_LISTS_MAX_SIZE | ||
) |
Increase the dimensions of a hashtable.
The hashtable H is re-organized to have NEW_ENTRIES_NB lists entries. Each entry is limited to NEW_LISTS_MAX_SIZE elements. After a call to this function, all insertions into H will make H automatically growing if needed. The grow is needed each time an insertion makes an entry list to reach NEW_LISTS_MAX_SIZE elements. In this case, H will be reorganized automatically by gdsl_hash_insert().
H | The hashtable to modify |
NEW_ENTRIES_NB | |
NEW_LISTS_MAX_SIZE |
gdsl_element_t gdsl_hash_search | ( | const gdsl_hash_t | H, |
const char * | KEY | ||
) |
Search for a particular element into a hashtable (GET).
Search the first element E equal to KEY in the hashtable H.
H | The hashtable to search the element in |
KEY | The key to compare H's elements with |
gdsl_element_t gdsl_hash_map | ( | const gdsl_hash_t | H, |
gdsl_map_func_t | MAP_F, | ||
void * | USER_DATA | ||
) |
Parse a hashtable.
Parse all elements of the hashtable H. The MAP_F function is called on each H's element with USER_DATA argument. If MAP_F returns GDSL_MAP_STOP then gdsl_hash_map() stops and returns its last examinated element.
H | The hashtable to map |
MAP_F | The map function. |
USER_DATA | User's datas passed to MAP_F |
void gdsl_hash_write | ( | const gdsl_hash_t | H, |
gdsl_write_func_t | WRITE_F, | ||
FILE * | OUTPUT_FILE, | ||
void * | USER_DATA | ||
) |
Write all the elements of a hashtable to a file.
Write the elements of the hashtable H to OUTPUT_FILE, using WRITE_F function. Additionnal USER_DATA argument could be passed to WRITE_F.
H | The hashtable to write. |
WRITE_F | The write function. |
OUTPUT_FILE | The file where to write H's elements. |
USER_DATA | User's datas passed to WRITE_F. |
void gdsl_hash_write_xml | ( | const gdsl_hash_t | H, |
gdsl_write_func_t | WRITE_F, | ||
FILE * | OUTPUT_FILE, | ||
void * | USER_DATA | ||
) |
Write the content of a hashtable to a file into XML.
Write the elements of the hashtable H to OUTPUT_FILE, into XML language. If WRITE_F != NULL, then uses WRITE_F to write H's elements to OUTPUT_FILE. Additionnal USER_DATA argument could be passed to WRITE_F.
H | The hashtable to write. |
WRITE_F | The write function. |
OUTPUT_FILE | The file where to write H's elements. |
USER_DATA | User's datas passed to WRITE_F. |
void gdsl_hash_dump | ( | const gdsl_hash_t | H, |
gdsl_write_func_t | WRITE_F, | ||
FILE * | OUTPUT_FILE, | ||
void * | USER_DATA | ||
) |
Dump the internal structure of a hashtable to a file.
Dump the structure of the hashtable H to OUTPUT_FILE. If WRITE_F != NULL, then uses WRITE_F to write H's elements to OUTPUT_FILE. Additionnal USER_DATA argument could be passed to WRITE_F.
H | The hashtable to write |
WRITE_F | The write function |
OUTPUT_FILE | The file where to write H's elements |
USER_DATA | User's datas passed to WRITE_F |