CK_HS_INIT(3)
π CK_HS_INIT(3) β the ck_hs_init manual, bestie edition π
okay so you're in the Concurrency Kit section of the manual (that's libck, link it with -lck), and today we're setting up a hash set. not reading from it, not writing to it β just birthing it. main character energy fr fr β¨
πΈ SYNOPSIS πΈ
#include <ck_hs.h>
typedef unsigned long
ck_hs_hash_cb_t(const void *key, unsigned long seed);
typedef bool
ck_hs_compare_cb_t(const void *c1, const void *c2);
bool
ck_hs_init(ck_hs_t *hs, unsigned int mode,
ck_hs_hash_cb_t *hash_function, ck_hs_compare_cb_t *compare,
struct ck_malloc *allocator, unsigned long capacity,
unsigned long seed);
like. look at her. she's gorgeous. π
π¦ DESCRIPTION π¦
so ck_hs_init() initializes the hash set that hs is pointing at. that's it. that's the job. she sets it up and hands you back a bool. no cap.
π the mode argument
mode tells us two things: what kind of key-value pairs you're storing, and what concurrent access model you expect. it's a bitfield, so you OR these together. let's go one by one because this is the part everyone skips and then gets confused about later π
key-value type vibes
CK_HS_MODE_OBJECTβ you're storing pointers to objects. this is a hint that onlyCK_MD_VMA_BITSare needed to encode the key argument, and any unused pointer bits get used for internal optimizations. little bit of free real estate, we love to see it. πCK_HS_MODE_DIRECTβ you're storing key values directly, and all the bits of the key are used to encode values. no free bits, no shortcuts, just the key, raw and unfiltered.
concurrent access model, aka who's allowed in the group chat
CK_HS_MODE_SPMCβ concurrent readers, single writer. one person types, everyone else reads. very "one person holds the aux" energy. π§CK_HS_MODE_MPMCβ concurrent readers and concurrent writers. > β οΈ bestie this one is currently unsupported. don't do it. it's giving unfinished business. π
extra workload hints (optional, but cute)
CK_HS_MODE_DELETEβ you expect a delete-heavy workload. at the cost of approximately 13% increased memory usage, it allows for stronger per-slot probe bounds to combat the effects of tombstone accumulation. yeah, tombstones. spooky. but worth it if you delete a lot. πͺ¦β¨
π the hash_function argument
mandatory!! pointer to a user-specified hash function. it takes two args:
keyβ a pointer to a key.seedβ the initial seed associated with the hash set. and where does that seed come from? you. you give it inck_hs_init(3). it's your seed, you chose it, own it. π±
π the compare argument
optional pointer to a user-specified key comparison function. if you pass NULL here, then pointer equality is what determines key equality. simple. iconic. if you do pass a function, it takes two arguments that are pointers to the objects being compared for equality, and it should return true if the keys are of equal value and false otherwise. that's the whole contract, no notes. π«Ά
π§ the allocator argument
a pointer to a struct containing malloc and free function pointers, which respectively define the memory allocation and destruction functions your hash set will use. you're in charge of the memory situation, we're just living in it.
β the capacity argument
the initial number of keys the hash set is expected to contain. important: this is just a hint. the underlying implementation is free to allocate more or less memory than necessary to contain the number of entries capacity specifies. so don't be weird about it.
πΈ the seed argument
the initial seed used by the underlying hash function. the user is free to choose a value of their choice. that's you. choose. π²
β¨ RETURN VALUES β¨
if it works, ck_hs_init() returns true. if it doesn't, it returns false to indicate an error. that's the whole story, short and sweet. π
π¨ ERRORS π¨
the behavior ofck_hs_init()is undefined ifhsis not a pointer to ack_hs_tobject.
read that again. not a warning. not a polite nudge. undefined behavior. pass her a real ck_hs_t or don't pass her anything at all. π€
π SEE ALSO π
ck_hs_move(3)ck_hs_destroy(3)CK_HS_HASH(3)ck_hs_iterator_init(3)ck_hs_next(3)ck_hs_get(3)ck_hs_put(3)ck_hs_put_unique(3)ck_hs_set(3)ck_hs_fas(3)ck_hs_remove(3)ck_hs_grow(3)ck_hs_rebuild(3)ck_hs_gc(3)ck_hs_count(3)ck_hs_reset(3)ck_hs_reset_size(3)ck_hs_stat(3)
additional info is available at http://concurrencykit.org/ β go read it, bestie, it's giving educational. π
okay that's the whole page!! this one's from Concurrency Kit, and the version we're looking at is dated September 17, 2012. love that for us. go init a hash set, you've got this π β¨π¦
π¦ where this page comes from
- alpine 3.24: ck-doc 0.7.2-r1 Β· BSD-2-Clause AND Apache-2.0
- debian trixie: libck-dev 0.7.2-6 Β· BSD-2-Clause
- epel 10: ck-devel 0.7.2-1.el10_1 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 43: ck-devel 0.7.2-2.fc43 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 43: ck-devel 0.7.2-2.fc43 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 44: ck-devel 0.7.2-4.fc44 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- fedora 44: ck-devel 0.7.2-4.fc44 Β· BSD-2-clause AND Apache-2.0 AND BSD-3-clause
- nixos 26.05: ck 0.7.2
- nixpkgs unstable: ck 0.7.2
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 Β· Apache-2.0 AND BSD-2-Clause
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 Β· Apache-2.0 AND BSD-2-Clause
- opensuse-leap 16.0: ck-devel 0.7.2-bp160.1.9 Β· Apache-2.0 AND BSD-2-Clause
- ubuntu questing: libck-dev 0.7.2-5ubuntu1
- ubuntu resolute: libck-dev 0.7.2-5ubuntu2 Β· BSD-2-Clause
- ubuntu stonking: libck-dev 0.7.2-11 Β· BSD-2-Clause
- Copyright 2012-2013 Samy Al Bahra
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms