CK_RHS_FAS(3)

✨ CK_RHS_FAS(3) ✨

okay bestie, gather round, because we're about to talk about fetch-and-store in a hash set and honestly? it's giving main character energy. this is the ck_rhs_fas page from the Concurrency Kit manual, and yes it lives in libck πŸ¦‹


🌸 LIBRARY 🌸

Concurrency Kit β€” link it with -lck and you're sooo good πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <ck_rhs.h>

bool
ck_rhs_fas(ck_rhs_t *hs, unsigned long hash, const void *key,
    void **previous);

πŸ’– DESCRIPTION πŸ’–

so. ck_rhs_fas(3) does two things at once and honestly the way it does that? iconic. it fetches and it stores the key you hand it in the hash set that hs points at πŸ”₯

the key you pass in as key is expected to already have the hash value you passed as hash β€” and no, you can't just make that number up, bestie, it has to have been generated earlier using the CK_RHS_HASH(3) macro. iykyk ✨

if the call to ck_rhs_fas(3) goes through, then your key was successfully stored in the hash set pointed to by hs, periodt. BUT β€” and this is the part people miss β€” the key must already exist in the hash set. it gets replaced by key, and the previous value gets tucked into the void pointer that previous points at 🫢

and if that key isn't in the hash set? the function returns false and the hash set stays exactly the way it was. no changes, no chaos, we love a clean no-op πŸ™ˆ

one more thing: this function is guaranteed to be stable with respect to memory usage. no sneaky allocations jumping out at you 🌈


⭐ RETURN VALUES ⭐

  • on success, ck_rhs_fas(3) returns true πŸ’–
  • otherwise it returns false on failure πŸ’€

😭 ERRORS 😭

behavior is undefined if key or hs are uninitialized. not "a little weird", not "maybe fine" β€” UNDEFINED. initialize your stuff, bestie, i'm begging 🧚

πŸ‘‘ SEE ALSO πŸ‘‘

additional info is available at http://concurrencykit.org/ 🌐


mwah that's the whole page πŸ’‹ this gem dropped June 20, 2013, and it ships with Concurrency Kit β€” so go forth, replace some keys, and stay stable with respect to memory usage πŸŒΈβœ¨πŸ’…

πŸ“¦ where this page comes from