90 struct cstl_hash_bucket
106 size_t count, capacity;
145#define CSTL_HASH_INITIALIZER(TYPE, MEMB) \
158 .off = offsetof(TYPE, MEMB), \
170#define DECLARE_CSTL_HASH(NAME, TYPE, MEMB) \
171 struct cstl_hash NAME = CSTL_HASH_INITIALIZER(TYPE, MEMB)
184 struct cstl_hash *
const h,
const size_t off)
188 h->bucket.capacity = 0;
190 h->bucket.hash = NULL;
192 h->bucket.rh.hash = NULL;
218 size_t count = h->bucket.count;
219 if (h->bucket.rh.hash != NULL) {
220 count = h->bucket.rh.count;
222 return (
float)h->count / count;
static void cstl_swap(void *const x, void *const y, void *const t, const size_t sz)
Swap values at two memory locations via use of a third.
void cstl_xtor_func_t(void *obj, void *priv)
Type for functions called to construct, clear, or destroy an object.
int cstl_visit_func_t(void *obj, void *priv)
Type for visit callbacks from objects supporting foreach.
int cstl_const_visit_func_t(const void *obj, void *priv)
Type for const visit callbacks from objects supporting foreach.
void cstl_hash_resize(struct cstl_hash *h, size_t n, cstl_hash_func_t *f)
Resize the hash table.
size_t cstl_hash_func_t(size_t k, size_t m)
Function type for hashing a key into a bucket.
float cstl_hash_load(const struct cstl_hash *const h)
Get the average number of nodes per bucket.
void cstl_hash_erase(struct cstl_hash *h, void *e)
Remove an object from the hash.
int cstl_hash_foreach_const(const struct cstl_hash *h, cstl_const_visit_func_t *visit, void *priv)
Visit each object within a hash table.
void * cstl_hash_find(struct cstl_hash *h, size_t k, cstl_const_visit_func_t *visit, void *priv)
Lookup/find a previously inserted object in the hash.
int cstl_hash_foreach(struct cstl_hash *h, cstl_visit_func_t *visit, void *priv)
Visit each object within a hash table.
static void cstl_hash_swap(struct cstl_hash *const a, struct cstl_hash *const b)
Swap the hash objects at the two given locations.
size_t cstl_hash_div(size_t k, size_t m)
Hash by division.
void cstl_hash_insert(struct cstl_hash *h, size_t k, void *e)
Insert an item into the hash.
void cstl_hash_shrink_to_fit(struct cstl_hash *h)
Free memory associated with excess buckets.
size_t cstl_hash_mul(size_t k, size_t m)
Hash by multiplication.
size_t cstl_hash_size(const struct cstl_hash *const h)
Get the number of objects in the hash.
static void cstl_hash_init(struct cstl_hash *const h, const size_t off)
Initialize a hash object.
void cstl_hash_clear(struct cstl_hash *h, cstl_xtor_func_t *clr)
Remove all elements from the hash.
void cstl_hash_rehash(struct cstl_hash *h)
Rehash the hash table.
Node to anchor an element within a hash.