libwget-hashmap(3)
π libwget-hashmap π
okay so bestie, welcome to libwget-hashmap β the hashmap girlies of the Library Functions Manual. She's a key/value store, she's fast, she's iconic, and by the end of this page you two are gonna be best friends. π¦β¨
πΈ NAME πΈ
libwget-hashmap β hashmap functions. That's it, that's the name, and honestly? It ate. π
β¨ SYNOPSIS β¨
π Functions
the whole friend group, assembled:
wget_hashmap_iterator * wget_hashmap_iterator_alloc (wget_hashmap *h)
void wget_hashmap_iterator_free (wget_hashmap_iterator **iter)
void * wget_hashmap_iterator_next (wget_hashmap_iterator *iter, void **value)
wget_hashmap * wget_hashmap_create (int max, wget_hashmap_hash_fn *hash, wget_hashmap_compare_fn *cmp)
int wget_hashmap_put (wget_hashmap *h, const void *key, const void *value)
int wget_hashmap_contains (const wget_hashmap *h, const void *key)
int wget_hashmap_get (const wget_hashmap *h, const void *key, void **value)
int wget_hashmap_remove (wget_hashmap *h, const void *key)
int wget_hashmap_remove_nofree (wget_hashmap *h, const void *key)
void wget_hashmap_free (wget_hashmap **h)
void wget_hashmap_clear (wget_hashmap *h)
int wget_hashmap_size (const wget_hashmap *h)
int wget_hashmap_browse (const wget_hashmap *h, wget_hashmap_browse_fn *browse, void *ctx)
void wget_hashmap_setcmpfunc (wget_hashmap *h, wget_hashmap_compare_fn *cmp)
int wget_hashmap_sethashfunc (wget_hashmap *h, wget_hashmap_hash_fn *hash)
void wget_hashmap_set_key_destructor (wget_hashmap *h, wget_hashmap_key_destructor *destructor)
void wget_hashmap_set_value_destructor (wget_hashmap *h, wget_hashmap_value_destructor *destructor)
void wget_hashmap_set_load_factor (wget_hashmap *h, float factor)
void wget_hashmap_set_resize_factor (wget_hashmap *h, float factor)
π§ The typedefs (aka the personality types)
typedef struct wget_hashmap_st wget_hashmapβ the actual Typeβ’ of the hashmap. main character energy, fr.typedef int wget_hashmap_compare_fn(const void *key1, const void *key2)β the type of the compare function. she's the one deciding if two keys are the same girl. πtypedef unsigned int wget_hashmap_hash_fn(const void *key)β the type of the hash function. turns your key into a number, no cap.typedef int wget_hashmap_browse_fn(void *ctx, const void *key, void *value)β the type of the browse callback. she gets called for every single element, so popular. πtypedef void wget_hashmap_key_destructor(void *key)β the type of the key destructor. she says bye to your keys, respectfully. π«Άtypedef void wget_hashmap_value_destructor(void *value)β the type of the value destructor. same energy, but for the values.
π Detailed Description π
Hashmaps are key/value stores that perform at O(1) for insertion, searching and removing.
likeβ¦ constant time?? in THIS economy?? we love to see it. ππ₯
π Function Documentation π
wget_hashmap_iterator_alloc()
wget_hashmap_iterator * wget_hashmap_iterator_alloc (wget_hashmap *h)
Parameters
hβ Hashmap
Returns
- New iterator instance for
h
Creates a hashmap iterator for h. fresh iterator, just dropped. β¨
wget_hashmap_iterator_free()
void wget_hashmap_iterator_free (wget_hashmap_iterator **iter)
Parameters
iterβ Hashmap iterator
Free the given iterator iter. say bye bestie π
wget_hashmap_iterator_next()
void * wget_hashmap_iterator_next (wget_hashmap_iterator *iter, void **value)
Parameters
iterβ Hashmap iteratorvalueβ Pointer to the value belonging to the returned key
Returns
- Pointer to the key or
NULLif no more elements left
Returns the next key / value in the hashmap. If all key/value pairs have been iterated over the function returns NULL and value is untouched.
When iterating over a hashmap, the order of returned key/value pairs is not defined. so do NOT come for me about the order, it's giving chaos and that's just her nature. π
wget_hashmap_create()
wget_hashmap * wget_hashmap_create (int max, wget_hashmap_hash_fn *hash, wget_hashmap_compare_fn *cmp)
Parameters
maxβ Initial number of pre-allocated entrieshashβ Hash function to build hashes from elementscmpβ 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).
π¨ bestie listen. skip settinghashandcmpand you're getting a segfault. that's not a vibe check, that's a crash. do it right the first time. π
wget_hashmap_put()
int wget_hashmap_put (wget_hashmap *h, const void *key, const void *value)
Parameters
hβ Hashmap to put data intokeyβ Key to insert intohvalueβ Value to insert intoh
Returns
0if inserted a new entry,1if entry existed,WGET_E_MEMORYif internal allocation failed
Insert a key/value pair into hashmap h.
key and value are not cloned, the hashmap takes 'ownership' of both. so like, she's your girl now, don't be weird about it.
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. key-only era, we stan a minimalist. π
Neither h nor key must be NULL, else the return value will always be 0.
wget_hashmap_contains()
int wget_hashmap_contains (const wget_hashmap *h, const void *key)
Parameters
hβ Hashmapkeyβ Key to search for
Returns
1ifkeyhas been found,0if not found
Check if key exists in h. she's either there or she's not, no in-between. π¦
wget_hashmap_get()
int wget_hashmap_get (const wget_hashmap *h, const void *key, void **value)
Parameters
hβ Hashmapkeyβ Key to search forvalueβ Value to be returned
Returns
1ifkeyhas been found,0if not found
Get the value for a given key.
Neither h nor key must be NULL. periodt.
wget_hashmap_remove()
int wget_hashmap_remove (wget_hashmap *h, const void *key)
Parameters
hβ Hashmapkeyβ Key to be removed
Returns
1ifkeyhas been removed,0if 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. so she goes out with a little ceremony. π
wget_hashmap_remove_nofree()
int wget_hashmap_remove_nofree (wget_hashmap *h, const void *key)
Parameters
hβ Hashmapkeyβ Key to be removed
Returns
1ifkeyhas been removed,0if not found
Remove key from hashmap h.
Key and value destructor functions are not called when removing the entry from the hashmap. ghosted, no goodbye text. π
wget_hashmap_free()
void wget_hashmap_free (wget_hashmap **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. the full send-off, every single one. π
wget_hashmap_clear()
void wget_hashmap_clear (wget_hashmap *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. the instance survives, just the contents are gone. iconic rebirth moment. β¨
wget_hashmap_size()
int wget_hashmap_size (const wget_hashmap *h)
Parameters
hβ Hashmap
Returns
- Number of entries in hashmap
h
Return the number of entries in the hashmap h. the headcount. π₯
wget_hashmap_browse()
int wget_hashmap_browse (const wget_hashmap *h, wget_hashmap_browse_fn *browse, void *ctx)
Parameters
hβ Hashmapbrowseβ Function to be called for each element ofhctxβ Context variable use as param tobrowse
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.
wget_hashmap_setcmpfunc()
void wget_hashmap_setcmpfunc (wget_hashmap *h, wget_hashmap_compare_fn *cmp)
Parameters
hβ Hashmapcmpβ Comparison function used to find keys
Set the comparison function.
wget_hashmap_sethashfunc()
int wget_hashmap_sethashfunc (wget_hashmap *h, wget_hashmap_hash_fn *hash)
Parameters
hβ Hashmaphashβ Hash function used to hash keys
Returns
WGET_E_SUCCESSif set successfully, elseWGET_E_MEMORYorWGET_E_INVALID
Set the key hash function.
The keys of all entries in the hashmap will be hashed again. This includes a memory allocation, so there is a possibility of failure. π«
wget_hashmap_set_key_destructor()
void wget_hashmap_set_key_destructor (wget_hashmap *h, wget_hashmap_key_destructor *destructor)
Parameters
hβ Hashmapdestructorβ Destructor function for keys
Set the key destructor function.
Default is free().
wget_hashmap_set_value_destructor()
void wget_hashmap_set_value_destructor (wget_hashmap *h, wget_hashmap_value_destructor *destructor)
Parameters
hβ Hashmapdestructorβ Destructor function for values
Set the value destructor function.
Default is free().
wget_hashmap_set_load_factor()
void wget_hashmap_set_load_factor (wget_hashmap *h, float factor)
Parameters
hβ Hashmapfactorβ 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.
wget_hashmap_set_resize_factor()
void wget_hashmap_set_resize_factor (wget_hashmap *h, float factor)
Parameters
hβ Hashmapfactorβ Hashmap growth factor
Set the factor for resizing the hashmap when it's load factor is reached.
The new size is 'factor * oldsize'. If the new size is less or equal 0, the involved put function will do nothing and the internal state of the hashmap will not change.
Default is 2.
π Author π
Generated automatically by Doxygen for wget2 from the source code. (not a human, not a girlie, just a doc generator doing her thing π )
okay that's the whole page bestie, you're officially fluent in libwget-hashmap. go forth and slay. π¦πβ¨
this lil masterpiece came from wget2, Version 2.3.0, and she lives at libwget-hashmap(3). mwah. π
π¦ where this page comes from
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-1.fc44
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- fedora 44: wget2-devel 2.3.0-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND GFDL-1.3-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms