ck_hs: add convenience hash function wrapper ck_hs_hash.

ck_hs_hash takes two arguments, the hash set and the key, then computes the
hash value. Performance gain from CK_HS_HASH is negligible with most workloads.
Basic test coverage in serial.c.

Shoutout to Theo Schlossnagle <jesus@circonus.com> who provided initial patch.
master
Samy Al Bahra 5 years ago
parent 78115831aa
commit 5723ec66ed

@ -109,6 +109,14 @@ typedef struct ck_hs_iterator ck_hs_iterator_t;
/* Convenience wrapper to table hash function. */
#define CK_HS_HASH(T, F, K) F((K), (T)->seed)
/* Computes the hash of n bytes of k for the specified hash map. */
static inline unsigned long
ck_hs_hash(const struct ck_hs *hs, const void *k)
{
return hs->hf(k, hs->seed);
}
typedef void *ck_hs_apply_fn_t(void *, void *);
bool ck_hs_apply(ck_hs_t *, unsigned long, const void *, ck_hs_apply_fn_t *, void *);
void ck_hs_iterator_init(ck_hs_iterator_t *);

@ -159,7 +159,14 @@ run_test(unsigned int is, unsigned int ad)
for (j = 0; j < size; j++) {
for (i = 0; i < sizeof(test) / sizeof(*test); i++) {
h = test[i][0];
unsigned long long h_1;
h = CK_HS_HASH(&hs[j], hs_hash, test[i]);
h_1 = ck_hs_hash(&hs[j], test[i]);
if (h != h_1)
ck_error("h != h_1 (%lu != %lu)\n", h, h_1);
if (ck_hs_get(&hs[j], h, test[i]) != NULL) {
continue;
}

Loading…
Cancel
Save