CK_HT_INIT(3)
π ck_ht_init β bestie, let's initialize a hash table π
okay so this is the ck_ht_init page from the CK_HT_INIT(3) manual, and it lives in the Concurrency Kit β that's libck, and you link it with -lck π
β¨ SYNOPSIS β¨
like, the whole vibe, exactly as it is:
#include <ck_ht.h>
typedef void
ck_ht_hash_cb_t(ck_ht_hash_t *h, const void *key, size_t key_length,
uint64_t seed);
bool
ck_ht_init(ck_ht_t *ht, enum ck_ht_mode mode,
ck_ht_hash_cb_t *hash_function, struct ck_malloc *allocator,
uint64_t capacity, uint64_t seed);
πΈ DESCRIPTION πΈ
So. ck_ht_init() initializes the hash table that ht points at. That's it, that's the whole job, and it ate π₯
the mode situation π
The mode argument says what kind of key-value pairs this table is gonna hold. mode can be one of these:
CK_HT_MODE_BYTESTRINGβ this table is meant to store key-value pointers where the key is a region of memory up to65536bytes long. That pointer gets dereferenced during hash table operations so keys can be compared. Entries of this table are expected to be interacted with using theck_ht_entry_empty(3),ck_ht_entry_key(3),ck_ht_entry_key_length(3),ck_ht_entry_value(3), andck_ht_entry_set(3)functions. Attempting a hash table operation with a key of valueNULLor(void *)UINTPTR_MAXwill result in undefined behavior. not me warning you bestie, this is real πCK_HT_MODE_DIRECTβ this table is meant to store key-value pointers where the key is a fixed width field compatible with theuintptr_ttype. The key gets directly compared with other keys for equality. Entries of this table are expected to be interacted with using theck_ht_entry_empty(3),ck_ht_entry_key_direct(3),ck_ht_entry_value_direct(3)andck_ht_entry_set_direct(3)functions. Attempting a hash table operation with a key of value of0orUINTPTR_MAXwill result in undefined behavior. π
plus you can OR in a lil extra π
On top of all that, you may bitwise OR the mode flag with CK_HT_WORKLOAD_DELETE to say that the hash table is gonna have to handle a delete heavy workload. In that case, stronger bounds on latency can be provided, at the cost of approximately 13% higher memory usage. a small price, honestly.
the hash_function thing π¦
The hash_function argument is a pointer to a user-specified hash function. It's optional β if NULL is specified, then the default hash function implementation gets used ( ck_ht_hash(3) ).
A user-specified hash function takes four arguments:
his a pointer to a hash value object. The hash function is expected to update the value object of typeuint64_tcontained with-in the object pointed to byh.keyis a pointer to a key.key_lengthis the length of the key.seedis the initial seed associated with the hash table. This initial seed is specified by the user inck_ht_init(3).
the allocator thing π
The allocator argument is a pointer to a structure containing malloc and free function pointers which respectively define the memory allocation and destruction functions to be used by the hash table being initialized. so like, your memory, your rules β¨
the capacity thing π
The capacity argument represents the initial number of key-value pairs the hash table is expected to contain. And here's the tea: this argument is simply a hint, and the underlying implementation is free to allocate more or less memory than necessary to contain the number of entries capacity specifies. it's giving "suggestion, not a contract" π
the seed thing β
The seed argument specifies the initial seed used by the underlying hash function. The user is free to choose a value of their choice. go wild bestie, pick whatever number speaks to you.
concurrency tea β
The hash table is safe to access by multiple readers in the presence of one concurrent writer. Behavior is undefined in the presence of concurrent writers. one writer. ONE. count them. π
π«Ά RETURN VALUES π«Ά
Upon successful completion ck_ht_init() returns a value of true, and otherwise returns a value of false to indicate an error. binary queen π
π ERRORS π
The behavior of ck_ht_init() is undefined if ht is not a pointer to a ck_ht_t object. like, don't do that. please.
π SEE ALSO π
the whole friend group, no cap:
ck_ht_stat(3),ck_ht_destroy(3),ck_ht_hash(3),ck_ht_hash_direct(3),ck_ht_set_spmc(3),ck_ht_put_spmc(3),ck_ht_gc(3),ck_ht_get_spmc(3),ck_ht_grow_spmc(3),ck_ht_remove_spmc(3),ck_ht_reset_spmc(3),ck_ht_reset_size_spmc(3),ck_ht_count(3),ck_ht_entry_empty(3),ck_ht_entry_key_set(3),ck_ht_entry_key_set_direct(3),ck_ht_entry_key(3),ck_ht_entry_key_length(3),ck_ht_entry_value(3),ck_ht_entry_set(3),ck_ht_entry_set_direct(3),ck_ht_entry_key_direct(3),ck_ht_entry_value_direct(3),ck_ht_iterator_init(3),ck_ht_next(3)
Additional information available at http://concurrencykit.org/ β go peek, it's cute π§
and that's the page bestie!! π this version was dated March 28, 2012 and filed under CK_HT_INIT(3) in the Concurrency Kit. mwah, go initialize something iconic β¨ππ¦
π¦ 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