CK_HS_APPLY(3)

πŸ’– ck_hs_apply β€” apply a function to hash set value πŸ’–

okay so bestie, this is ck_hs_apply(3) from the Concurrency Kit, and it lives in libck β€” you link it with -lck. that's literally it. it's giving "tiny function, huge power" energy and i'm obsessed 🫢


✨ LIBRARY ✨

Concurrency Kit (libck, -lck) β€” yeah you're gonna want to pass -lck to your linker or none of this slays πŸ’…


🌸 SYNOPSIS 🌸

so here's the tea, this is exactly what you write:

#include <ck_hs.h>

void *
ck_hs_apply_fn_t(void *key, void *closure);

bool
ck_hs_apply(ck_hs_t *hs, unsigned long hash, const void *key,
    ck_hs_apply_fn_t *function, void *argument);

like, look at that callback signature. void * in, void * out. main character energy fr fr 🌟


πŸ’… DESCRIPTION πŸ’…

okay so real talk. ck_hs_apply(3) goes and looks up the hash set slot associated with key, and then hands it straight to the function pointed to by function so it can do whatever it wants with it. like a little handoff. a relay race. passing the baton πŸƒβ™€οΈβœ¨

and here's the spicy part: that callback is allowed to remove or replace the value. how? by returning NULL (that's the removal arc, bye bestie πŸ‘‹) or by returning a pointer to another object that has an identical key (that's the glow-up arc ✨). either way, the callback is the one making the call.

so, the arguments your function gets:

  1. the first argument is a pointer to the object that was found in the hash set. that's your target, your found item, your moment 🌸
  2. the second argument is the argument pointer that got passed into ck_hs_apply(3). yes, it just gets forwarded straight through to you. convenient!

and one lil detail that matters a lot: if the pointer your function returns is equivalent to the first argument, then no modification is made to the hash set. nothing happens. the set stays exactly as it was. no cap, it just shrugs and moves on πŸ™ˆ


🌈 RETURN VALUES 🌈

that's the whole vibe check. true or false, no in-between, no crumbs.


πŸŽ€ SEE ALSO πŸŽ€

the whole girlies of the hash set family, go read them too:

and if you want even more, there's Additional information available at http://concurrencykit.org/ 🌐


kisses, this page is from September 1, 2014, it's CK_HS_APPLY(3), and that's the whole manual bestie β€” go apply some functions πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from