CK_HT_GROW_SPMC(3)

๐Ÿ’– ck_ht_grow_spmc(3) โ€” the manual page, but make it make sense ๐Ÿ’–

okay bestie, so this is ck_ht_grow_spmc, and it lives in section 3 of the manual (the "library functions" section, iykyk). it's a Concurrency Kit thing, and no cap, it's genuinely useful. let's get into it ๐Ÿซถ


๐ŸŒธ LIBRARY ๐ŸŒธ

Concurrency Kit โ€” that's libck, and you link it with -lck. periodt. ๐Ÿ’…


โœจ SYNOPSIS โœจ

#include <ck_ht.h>

bool
ck_ht_grow_spmc(ck_ht_t *ht, uint64_t capacity);

likeโ€ฆ that's the whole vibe. two arguments, one bool coming back at you. ๐ŸŽ€


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so here's the tea, bestie: ck_ht_grow_spmc() resizes the hash table so that it can hold at least the number of entries you passed in as capacity โ€” and it does that at a load factor of one. slay.

but wait, there's lore. the default load factor of a ck_ht hash table is 0.5. so if you're out here trying to minimize the likelihood of memory allocations for a hash table that's meant to store n entries, you should pass a capacity of 2n. do the math, trust. ๐Ÿงฎโœจ

also, the default behavior of ck_ht is to round capacity to the next available power of two if it isn't already a power of two. so don't come for it when your numbers shift โ€” that's just how it do. ๐Ÿ˜Œ

and the moment you've all been waiting for: this function is safe to call in the presence of concurrent ck_ht_get_spmc(3) operations. concurrency? handled. main character energy only. ๐Ÿ‘‘


๐Ÿ’œ RETURN VALUES ๐Ÿ’œ

  • on a successful completion, ck_ht_grow_spmc() returns true ๐ŸŽ‰
  • otherwise it returns a false value ๐Ÿ˜ญ

that's it. that's the return value situation. fr fr.


๐Ÿ’€ ERRORS ๐Ÿ’€

โš ๏ธ behavior is undefined if ht is uninitialized. like, don't do that. don't be that girl.

the function will only return false if there are internal memory allocation failures. that's the only reason. no other drama. ๐Ÿ™ˆ


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ

the whole friend group, in alphabetical-ish order, exactly as the original intended:

and if you want even more info, the original says it's available at http://concurrencykit.org/ ๐ŸŒˆ โ€” go read up, bestie, knowledge is free and it's giving scholar.


and that's a wrap on the ck_ht_grow_spmc(3) manual page ๐ŸŽ€โœจ this version is from March 29, 2012, and it ships with Concurrency Kit โ€” so if you're repping that libck life, you're in the right place. stay growing, stay concurrent, stay iconic. mwah ๐Ÿ’…๐Ÿ’–

๐Ÿ“ฆ where this page comes from