qt_dictionary_create(3)

πŸ“¦ version 1.22^20251007gitcedb1fc, in fedora 43, fedora 44

✨ 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 eq function, which it uses to compare keys
  • the hash function, which converts a key into an integer
  • the cleanup function, 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 πŸ”₯

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