qt_dictionary_create(3)
β¨ qt_dictionary_create β¨
okay bestie, welcome to libqthread's dictionary page π this is qt_dictionary_create(3) and we're gonna make a whole concurrent dictionary together, no cap.
πΈ NAME πΈ
qt_dictionary_create β allocate a concurrent dictionary ποΈβ¨
π¦ SYNOPSIS π¦
#include <qthread/dictionary.h>
qt_dictionary *
qt_dictionary_create (qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_tag_cleanup_f cleanup);
π DESCRIPTION π
So like, this function makes you a dictionary data structure. iconic. it's giving "let me hold your stuff." and the way it does that is by taking three little helper functions from you:
- the
eqfunction, which it uses to compare keys - the
hashfunction, which converts a key into an integer - the
cleanupfunction, which deallocates tags when the dictionary gets destroyed π§
fr fr, you're handing it the whole personality of your dictionary.
π the eq function
the prototype of the key comparison function is:
int eq(void *key1, void *key2);
eq should return one if the keys are equal and zero otherwise. that's it, that's the whole job. queen behavior π
π the hash function
the prototype of the key conversion function is:
int hash(void *key);
hash may return any value. literally any. go wild. BUT. and this is the big one, bestie:
the following property MUST be maintained: c if (eq(A, B) == 1) then hash(A) == hash(B)
like, if two keys are equal, their hashes have to match too. that is not optional, that is not a suggestion, that is the LAW of this dictionary. break it and everything falls apart π
π the cleanup function
the prototype of the cleanup function is:
void cleanup(void *key);
cleanup is your little hook to deallocate keys as necessary β it's there so you can free stuff when you need to. and here's the cute part: the function pointer may be NULL. so if you don't need it, you don't have to bring it. lowkey freeing. π«Ά
π RETURN VALUES π
returns an initialized qt_dictionary object. that's it. that's the gift. a whole dictionary, ready for you. slay. π
π₯ SEE ALSO π₯
qt_dictionary_delete(3)qt_dictionary_destroy(3)qt_dictionary_end(3)qt_dictionary_get(3)qt_dictionary_iterator_copy(3)qt_dictionary_iterator_create(3)qt_dictionary_iterator_destroy(3)qt_dictionary_iterator_equals(3)qt_dictionary_iterator_get(3)qt_dictionary_iterator_next(3)qt_dictionary_put(3)qt_dictionary_put_if_absent(3)
the whole friend group, all in one place π«β¨
and that's the page, bestie π this was libqthread, version AUGUST 2012, and honestly? a classic. obsessed. periodt. π
π¦ where this page comes from
- fedora 43: qthreads-devel 1.22^20251007gitcedb1fc-1.fc43 Β· BSD-3-Clause AND MIT AND dtoa
- fedora 44: qthreads-devel 1.22^20251007gitcedb1fc-2.fc44 Β· BSD-3-Clause AND MIT AND dtoa
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms