qt_dictionary_put_if_absent(3)

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

✨ qt_dictionary_put_if_absent(3) ✨

okay bestie, so this page lives in the libqthread manual section 3, and it's about one very specific little function: qt_dictionary_put_if_absent. yes the name is a whole sentence, we love a descriptive queen πŸ’…


πŸŽ€ NAME πŸŽ€

qt_dictionary_put_if_absent β€” insert a key/value pair into a dictionary

like... it puts stuff in. but conditionally. main character behaviour honestly 🫢


🌸 SYNOPSIS 🌸

#include <qthread/dictionary.h>

void *
qt_dictionary_put_if_absent (qt_dictionary *dict,
                             void *key,
                             void *value);

so you gotta #include <qthread/dictionary.h> first, no cap, or nothing works. then you call it with your dict, your key, and your value, and it hands you back a void *. cute. simple. iconic. ✨


πŸ’– DESCRIPTION πŸ’–

okay so here's the tea πŸ“ β€” this function inserts a key/value pair into the dictionary dict. the pair is made of the key and the value you pass in, periodt.

but here's the plot twist: the insertion will fail if the key is already present in the dictionary. it literally says if absent in the name bestie, it's not playing games. if that key is already in there? nope. insert denied. πŸ’€

so if you're looking for "just overwrite whatever's there," this is not that function. this one is the only if it's not there yet function. vibe check: passed, but conditionally. 🌈


πŸ‘‘ RETURN VALUES πŸ‘‘

it returns the address of the item in the dictionary after the put, OR NULL if the insert failed 😭

so like β€” got a real pointer back? slay, it worked. got NULL? the key was already there, the insert didn't happen, we move on. no drama, just facts. ✨

ngl bestie, always check for NULL. that's your whole signal that nothing got inserted. πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹

the whole dictionary friend group, all here, all iconic:


and that's the whole page, bestie!! this came to you straight from libqthread, dated AUGUST 2012 β€” yes she's vintage, yes she still serves πŸ’œ go put something in a dictionary (only if it's absent, we've been over this) πŸŽ€βœ¨

πŸ“¦ where this page comes from