table of contents
libwget-stringmap(3) | wget2 | libwget-stringmap(3) |
NAME¶
libwget-stringmap - Stringmap functions
SYNOPSIS¶
Functions¶
wget_stringmap_t * wget_stringmap_create (int max)
wget_stringmap_t * wget_stringmap_create_nocase (int max)
int wget_stringmap_put_noalloc (wget_stringmap_t *h, const char *key,
const void *value)
int wget_stringmap_put (wget_stringmap_t *h, const char *key, const
void *value, size_t valuesize)
int wget_stringmap_get_null (const wget_stringmap_t *h, const char
*key, void **value)
void * wget_stringmap_get (const wget_stringmap_t *h, const char *key)
int wget_stringmap_contains (const wget_stringmap_t *h, const char
*key)
int wget_stringmap_remove (wget_stringmap_t *h, const char *key)
int wget_stringmap_remove_nofree (wget_stringmap_t *h, const char *key)
void wget_stringmap_free (wget_stringmap_t **h)
void wget_stringmap_clear (wget_stringmap_t *h)
int wget_stringmap_size (const wget_stringmap_t *h)
int wget_stringmap_browse (const wget_stringmap_t *h,
wget_stringmap_browse_t browse, void *ctx)
void wget_stringmap_setcmpfunc (wget_stringmap_t *h,
wget_stringmap_compare_t cmp)
void wget_stringmap_sethashfunc (wget_stringmap_t *h,
wget_stringmap_hash_t hash)
void wget_stringmap_set_key_destructor (wget_hashmap_t *h,
wget_stringmap_key_destructor_t destructor)
void wget_stringmap_set_value_destructor (wget_hashmap_t *h,
wget_stringmap_value_destructor_t destructor)
void wget_stringmap_setloadfactor (wget_stringmap_t *h, float factor)
void wget_stringmap_set_growth_policy (wget_stringmap_t *h, int off)
Detailed Description¶
Stringmaps are key/value stores that perform at O(1) for insertion, searching and removing. The key is a C string.
These functions are a wrapper around the Hashmap API.
Function Documentation¶
wget_stringmap_t* wget_stringmap_create (int max)¶
Parameters
Returns
Create a new stringmap instance with initial size max. It should be free'd after use with wget_stringmap_free().
The hash function is an efficient string hash algorithm originally researched by Paul Larson.
The compare function is strcmp(). The key strings are compared case-sensitive.
wget_stringmap_t* wget_stringmap_create_nocase (int max)¶
Parameters
Returns
Create a new stringmap instance with initial size max. It should be free'd after use with wget_stringmap_free().
The hash function is an efficient string hash algorithm originally researched by Paul Larson, using lowercase'd keys.
The compare function is strcasecmp() (case-insensitive).
int wget_stringmap_put_noalloc (wget_stringmap_t * h, const char * key, const void * value)¶
Parameters
key Key to insert into h
value Value to insert into h
Returns
Insert a key/value pair into stringmap h.
key and value are not cloned, the stringmap 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_stringmap_put (wget_stringmap_t * h, const char * key, const void * value, size_t valuesize)¶
Parameters
key Key to insert into h
value Value to insert into h
valuesize Size of value
Returns
Insert a key/value pair into stringmap 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_stringmap_get_null (const wget_stringmap_t * h, const char * key, void ** value)¶
Parameters
key Key to search for
value Value to be returned
Returns
Get the value for a given key.
If there are NULL values in the stringmap, you should use this function to distinguish between 'not found' and 'found NULL value'.
Neither h nor key must be NULL.
void* wget_stringmap_get (const wget_stringmap_t * h, const char * key)¶
Parameters
key Key to search for
Returns
Get the value for a given key.
If there are NULL values in the stringmap, you should use wget_stringmap_get_null() to distinguish between 'not found' and 'found NULL value'.
Neither h nor key must be NULL.
int wget_stringmap_contains (const wget_stringmap_t * h, const char * key)¶
Parameters
key Key to search for
Returns
Check if key exists in h.
int wget_stringmap_remove (wget_stringmap_t * h, const char * key)¶
Parameters
key Key to be removed
Returns
Remove key from stringmap h.
If key is found, the key and value destructor functions are called when removing the entry from the stringmap.
int wget_stringmap_remove_nofree (wget_stringmap_t * h, const char * key)¶
Parameters
key Key to be removed
Returns
Remove key from stringmap h.
Key and value destructor functions are not called when removing the entry from the stringmap.
void wget_stringmap_free (wget_stringmap_t ** h)¶
Parameters
Remove all entries from stringmap h and free the stringmap instance.
Key and value destructor functions are called for each entry in the stringmap.
void wget_stringmap_clear (wget_stringmap_t * h)¶
Parameters
Remove all entries from stringmap h.
Key and value destructor functions are called for each entry in the stringmap.
int wget_stringmap_size (const wget_stringmap_t * h)¶
Parameters
Returns
Return the number of entries in the stringmap h.
int wget_stringmap_browse (const wget_stringmap_t * h, wget_stringmap_browse_t browse, void * ctx)¶
Parameters
browse Function to be called for each element of h
ctx Context variable use as param to browse
Returns
Call function browse for each element of stringmap 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_stringmap_setcmpfunc (wget_stringmap_t * h, wget_stringmap_compare_t cmp)¶
Parameters
cmp Comparison function used to find keys
Set the comparison function.
void wget_stringmap_sethashfunc (wget_stringmap_t * h, wget_stringmap_hash_t hash)¶
Parameters
hash Hash function used to hash keys
Set the key hash function.
The keys of all entries in the stringmap will be hashed again.
void wget_stringmap_set_key_destructor (wget_hashmap_t * h, wget_stringmap_key_destructor_t destructor)¶
Parameters
destructor Destructor function for keys
Set the key destructor function.
Default is free().
void wget_stringmap_set_value_destructor (wget_hashmap_t * h, wget_stringmap_value_destructor_t destructor)¶
Parameters
destructor Destructor function for values
Set the value destructor function.
Default is free().
void wget_stringmap_setloadfactor (wget_stringmap_t * h, float factor)¶
Parameters
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_stringmap_set_growth_policy().
The resize (and rehashing) occurs earliest on the next insertion of a new key.
Default is 0.75.
void wget_stringmap_set_growth_policy (wget_stringmap_t * h, int off)¶
Parameters
off Stringmap 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.
Tue Jan 26 2021 | Version 1.99.1 |