CK_HT_PUT_SPMC(3)

πŸ’– CK_HT_PUT_SPMC πŸ’–

okay so bestie, welcome to ck_ht_put_spmc(3) β€” yes that's the manual page name, and yes it lives in section 3 of the manual, we love a section 3 moment 🫢

This one's part of Concurrency Kit, aka libck, and you link it with -lck. Iconic library, no cap. ✨


🌸 SYNOPSIS 🌸

#include <ck_ht.h>

bool
ck_ht_put_spmc(ck_ht_t *ht, ck_ht_hash_t h, ck_ht_entry_t *entry);

look at her. three little args. so demure. πŸ’…


✨ DESCRIPTION ✨

so what does ck_ht_put_spmc() actually do? she stores the key-value pair you specified in the entry argument into the hash table pointed to by the ht argument. that's the whole gig. πŸŽ€

and here's the thing β€” the key you put in entry is expected to have the hash value specified by the h argument. like, you already did that part, girl. she's not doing it for you.

now, the mode check, because it matters:

  • if ht was created with CK_HT_MODE_BYTESTRING, then entry must have been initialized with the ck_ht_entry_set(3) function.
  • if ht was created with CK_HT_MODE_DIRECT, then entry must have been initialized with the ck_ht_entry_set_direct(3) function.

and same energy for the hash value h:

  • it's expected that h was initialized with ck_ht_hash(3) if ht was created with CK_HT_MODE_BYTESTRING.
  • if ht was initialized with CK_HT_MODE_DIRECT, then it's expected that h was initialized with the ck_ht_hash_direct(3) function.

if the call to ck_ht_put_spmc() was successful, then the key-value pair in entry was successfully stored in the hash table pointed to by ht β€” and it will fail if the key specified in entry already exists with-in the hash table. πŸ’€ yes, this one is strictly insert-only, she does NOT overwrite.

so if you wanted replace-y, swap-her-out energy? that's not this function. replacement semantics are provided by the ck_ht_set_spmc(3) function. go ask her. πŸ™ˆ

one more thing and it's a big one: this function is safe to call in the presence of concurrent ck_ht_get_spmc(3) operations. main character energy, honestly. πŸ”₯


🌈 RETURN VALUES 🌈

upon successful completion, ck_ht_put_spmc() returns true. otherwise she returns false on failure. binary. simple. slay. ✨


πŸ’€ ERRORS πŸ’€

okay bestie, listen up, this part is the serious part:

behavior is undefined if entry or ht are uninitialized. not "kinda weird", not "returns garbage" β€” undefined. we do not play with that. 🚨

the function will return false if:

  • the hash table required to be grown but failed while attempting to grow, or
  • the key specified in entry was already present in the hash table.

that's it, that's the list. 😭


πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, fr fr:

ck_ht_stat(3), ck_ht_init(3), ck_ht_destroy(3), ck_ht_hash(3), ck_ht_hash_direct(3), ck_ht_set_spmc(3), ck_ht_gc(3), ck_ht_get_spmc(3), ck_ht_grow_spmc(3), ck_ht_remove_spmc(3), ck_ht_reset_spmc(3), ck_ht_reset_size_spmc(3), ck_ht_count(3), ck_ht_entry_empty(3), ck_ht_entry_key_set(3), ck_ht_entry_key_set_direct(3), ck_ht_entry_key(3), ck_ht_entry_key_length(3), ck_ht_entry_value(3), ck_ht_entry_set(3), ck_ht_entry_set_direct(3), ck_ht_entry_key_direct(3), ck_ht_entry_value_direct(3), ck_ht_iterator_init(3), ck_ht_next(3)

additional information available at http://concurrencykit.org/ 🌐


and that's the page!! mwah πŸ’‹ this little beauty is from March 29, 2012 β€” yeah she's an elder but she ate and left no crumbs β€” and it's the CK_HT_PUT_SPMC(3) page out of the Concurrency Kit source, version-wise. go forth and insert, bestie. πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from