CK_HS_GROW(3)

πŸ’– CK_HS_GROW πŸ’–

okay bestie, gather round, because we're about to talk about the glow-up function of the Concurrency Kit hash set world πŸ¦‹

This page lives in the Concurrency Kit β€” that's libck, and you link it with -lck, no cap πŸ’…


✨ SYNOPSIS ✨

#include <ck_hs.h>

bool
ck_hs_grow(ck_hs_t *hs, unsigned long capacity);

🌸 DESCRIPTION 🌸

So ck_hs_grow(3) is literally the function that makes your hash set ✨bigger✨. It resizes the hash set so it can store at least the number of entries you pass in as capacity β€” and it does that at a load factor of one. iconic behavior honestly πŸ‘‘

quick lil reminder though: the default hash set load factor is 0.5, not 1. so yeah, she's a little roomier than default by design 🫢

now here's the tea β˜• β€” if you want to minimize the likelihood of memory allocations for a hash set that's meant to store n entries, then you should specify a capacity of 2n. that's the move, fr fr.

and one more thing: the default behavior of ck_hs is to round capacity up to the next power of two if it's not already a power of two. so don't be surprised when your cute lil number comes back different πŸ’€ it's giving mathematically responsible.


πŸ’œ RETURN VALUES πŸ’œ

  • If everything goes great, ck_hs_grow(3) returns true πŸŽ€
  • If it does not go great, it returns false 😭

that's it. that's the whole vibe check.


πŸ™ˆ ERRORS πŸ™ˆ

⚠️ Behavior is undefined if hs is uninitialized. like, genuinely undefined. don't do it. this is not a drill, bestie πŸ’€

and the only reason this function will return false is if there are internal memory allocation failures. so if it fails, it's not you, it's the memory 🌈


πŸ‘‘ SEE ALSO πŸ‘‘

the whole squad, obviously:

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


okay that's the whole page, ily, go grow your hash set responsibly πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

this lil masterpiece was dated September 17, 2012, and it's the CK_HS_GROW(3) page β€” periodt. πŸ’œ

πŸ“¦ where this page comes from