Provided by: wget2-dev_1.99.1-2.2_amd64
NAME
libwget-hashmap - Hashmap functions
SYNOPSIS
Functions wget_hashmap_t * wget_hashmap_create (int max, wget_hashmap_hash_t hash, wget_hashmap_compare_t cmp) int wget_hashmap_put_noalloc (wget_hashmap_t *h, const void *key, const void *value) int wget_hashmap_put (wget_hashmap_t *h, const void *key, size_t keysize, const void *value, size_t valuesize) int wget_hashmap_get_null (const wget_hashmap_t *h, const void *key, void **value) void * wget_hashmap_get (const wget_hashmap_t *h, const void *key) int wget_hashmap_contains (const wget_hashmap_t *h, const void *key) int wget_hashmap_remove (wget_hashmap_t *h, const void *key) int wget_hashmap_remove_nofree (wget_hashmap_t *h, const void *key) void wget_hashmap_free (wget_hashmap_t **h) void wget_hashmap_clear (wget_hashmap_t *h) int wget_hashmap_size (const wget_hashmap_t *h) int wget_hashmap_browse (const wget_hashmap_t *h, wget_hashmap_browse_t browse, void *ctx) void wget_hashmap_setcmpfunc (wget_hashmap_t *h, wget_hashmap_compare_t cmp) void wget_hashmap_sethashfunc (wget_hashmap_t *h, wget_hashmap_hash_t hash) void wget_hashmap_set_key_destructor (wget_hashmap_t *h, wget_hashmap_key_destructor_t destructor) void wget_hashmap_set_value_destructor (wget_hashmap_t *h, wget_hashmap_value_destructor_t destructor) void wget_hashmap_setloadfactor (wget_hashmap_t *h, float factor) void wget_hashmap_set_growth_policy (wget_hashmap_t *h, int off)
Detailed Description
Hashmaps are key/value stores that perform at O(1) for insertion, searching and removing.
Function Documentation
wget_hashmap_t* wget_hashmap_create (int max, wget_hashmap_hash_t hash, wget_hashmap_compare_t cmp) Parameters max Initial number of pre-allocated entries hash Hash function to build hashes from elements cmp Comparison function used to find elements Returns New hashmap instance Create a new hashmap instance with initial size max. It should be free'd after use with wget_hashmap_free(). Before the first insertion of an element, hash and cmp must be set. So if you use NULL values here, you have to call wget_hashmap_setcmpfunc() and/or wget_hashmap_hashcmpfunc() with appropriate function pointers. No doing so will result in undefined behavior (likely you'll see a segmentation fault). int wget_hashmap_put_noalloc (wget_hashmap_t * h, const void * key, const void * value) Parameters h Hashmap to put data into key Key to insert into h value Value to insert into h Returns 0 if inserted a new entry, 1 if entry existed Insert a key/value pair into hashmap h. key and value are not cloned, the hashmap takes 'ownership' of both. If key already exists and the pointer values the old and the new key differ, the old key will be destroyed by calling the key destructor function (default is free()). To realize a hashset (just keys without values), value may be NULL. Neither h nor key must be NULL. int wget_hashmap_put (wget_hashmap_t * h, const void * key, size_t keysize, const void * value, size_t valuesize) Parameters h Hashmap to put data into key Key to insert into h keysize Size of key value Value to insert into h valuesize Size of value Returns 0 if inserted a new entry, 1 if entry existed Insert a key/value pair into hashmap h. If key already exists it will not be cloned. In this case the value destructor function will be called with the old value and the new value will be shallow cloned. If doesn't exist, both key and value will be shallow cloned. To realize a hashset (just keys without values), value may be NULL. Neither h nor key must be NULL. int wget_hashmap_get_null (const wget_hashmap_t * h, const void * key, void ** value) Parameters h Hashmap key Key to search for value Value to be returned Returns 1 if key has been found, 0 if not found Get the value for a given key. If there are NULL values in the hashmap, you should use this function to distinguish between 'not found' and 'found NULL value'. Neither h nor key must be NULL. void* wget_hashmap_get (const wget_hashmap_t * h, const void * key) Parameters h Hashmap key Key to search for Returns Found value or NULL if not found Get the value for a given key. If there are NULL values in the hashmap, you should use wget_hashmap_get_null() to distinguish between 'not found' and 'found NULL value'. Neither h nor key must be NULL. int wget_hashmap_contains (const wget_hashmap_t * h, const void * key) Parameters h Hashmap key Key to search for Returns 1 if key has been found, 0 if not found Check if key exists in h. int wget_hashmap_remove (wget_hashmap_t * h, const void * key) Parameters h Hashmap key Key to be removed Returns 1 if key has been removed, 0 if not found Remove key from hashmap h. If key is found, the key and value destructor functions are called when removing the entry from the hashmap. int wget_hashmap_remove_nofree (wget_hashmap_t * h, const void * key) Parameters h Hashmap key Key to be removed Returns 1 if key has been removed, 0 if not found Remove key from hashmap h. Key and value destructor functions are not called when removing the entry from the hashmap. void wget_hashmap_free (wget_hashmap_t ** h) Parameters h Hashmap to be free'd Remove all entries from hashmap h and free the hashmap instance. Key and value destructor functions are called for each entry in the hashmap. void wget_hashmap_clear (wget_hashmap_t * h) Parameters h Hashmap to be cleared Remove all entries from hashmap h. Key and value destructor functions are called for each entry in the hashmap. int wget_hashmap_size (const wget_hashmap_t * h) Parameters h Hashmap Returns Number of entries in hashmap h Return the number of entries in the hashmap h. int wget_hashmap_browse (const wget_hashmap_t * h, wget_hashmap_browse_t browse, void * ctx) Parameters h Hashmap browse Function to be called for each element of h ctx Context variable use as param to browse Returns Return value of the last call to browse Call function browse for each element of hashmap h or until browse returns a value not equal to zero. browse is called with ctx and the pointer to the current element. The return value of the last call to browse is returned or 0 if either h or browse is NULL. void wget_hashmap_setcmpfunc (wget_hashmap_t * h, wget_hashmap_compare_t cmp) Parameters h Hashmap cmp Comparison function used to find keys Set the comparison function. void wget_hashmap_sethashfunc (wget_hashmap_t * h, wget_hashmap_hash_t hash) Parameters h Hashmap hash Hash function used to hash keys Set the key hash function. The keys of all entries in the hashmap will be hashed again. void wget_hashmap_set_key_destructor (wget_hashmap_t * h, wget_hashmap_key_destructor_t destructor) Parameters h Hashmap destructor Destructor function for keys Set the key destructor function. Default is free(). void wget_hashmap_set_value_destructor (wget_hashmap_t * h, wget_hashmap_value_destructor_t destructor) Parameters h Hashmap destructor Destructor function for values Set the value destructor function. Default is free(). void wget_hashmap_setloadfactor (wget_hashmap_t * h, float factor) Parameters h Hashmap factor The load factor Set the load factor function. The load factor is determines when to resize the internal memory. 0.75 means 'resize if 75% or more of all slots are used'. The resize strategy is set by wget_hashmap_set_growth_policy(). The resize (and rehashing) occurs earliest on the next insertion of a new key. Default is 0.75. void wget_hashmap_set_growth_policy (wget_hashmap_t * h, int off) Parameters h Hashmap off Hashmap growth mode: positive values: increase size by off entries on each resize negative values: increase size by multiplying -off, e.g. -2 doubles the size on each resize Set the growth policy for internal memory. Default is -2.
Author
Generated automatically by Doxygen for wget2 from the source code.