Skip to content

Commit

Permalink
ck_hs: add convenience hash function wrapper ck_hs_hash.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Samy Al Bahra committed Jul 2, 2020
1 parent 7811583 commit 5723ec6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/ck_hs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
9 changes: 8 additions & 1 deletion regressions/ck_hs/validate/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5723ec6

Please sign in to comment.