ck_hs: Add hash function wrapper to maintain opacity of ck_hs_t.

This is in the form of CK_HS_HASH(X, Y, Z) which expands to
Y(Z, X.seed).
ck_pring
Samy Al Bahra 12 years ago
parent 43b24d9f28
commit 690782aa67

@ -83,6 +83,9 @@ typedef struct ck_hs_iterator ck_hs_iterator_t;
#define CK_HS_ITERATOR_INITIALIZER { NULL, 0 } #define CK_HS_ITERATOR_INITIALIZER { NULL, 0 }
/* Convenience wrapper to table hash function. */
#define CK_HS_HASH(T, F, K) F((K), (T)->seed)
void ck_hs_iterator_init(ck_hs_iterator_t *); void ck_hs_iterator_init(ck_hs_iterator_t *);
bool ck_hs_next(ck_hs_t *, ck_hs_iterator_t *, void **); bool ck_hs_next(ck_hs_t *, ck_hs_iterator_t *, void **);
bool ck_hs_init(ck_hs_t *, unsigned int, ck_hs_hash_cb_t *, ck_hs_compare_cb_t *, struct ck_malloc *, unsigned long, unsigned long); bool ck_hs_init(ck_hs_t *, unsigned int, ck_hs_hash_cb_t *, ck_hs_compare_cb_t *, struct ck_malloc *, unsigned long, unsigned long);

@ -154,7 +154,7 @@ set_remove(const char *value)
{ {
unsigned long h; unsigned long h;
h = (unsigned long)MurmurHash64A(value, strlen(value), hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
return (bool)ck_hs_remove(&hs, h, value); return (bool)ck_hs_remove(&hs, h, value);
} }
@ -164,7 +164,7 @@ set_replace(const char *value)
unsigned long h; unsigned long h;
void *previous; void *previous;
h = (unsigned long)MurmurHash64A(value, strlen(value), hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
return ck_hs_set(&hs, h, value, &previous); return ck_hs_set(&hs, h, value, &previous);
} }
@ -174,7 +174,7 @@ set_get(const char *value)
unsigned long h; unsigned long h;
void *v; void *v;
h = (unsigned long)MurmurHash64A(value, strlen(value), hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
v = ck_hs_get(&hs, h, value); v = ck_hs_get(&hs, h, value);
return v; return v;
} }
@ -184,7 +184,7 @@ set_insert(const char *value)
{ {
unsigned long h; unsigned long h;
h = (unsigned long)MurmurHash64A(value, strlen(value), hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
return ck_hs_put(&hs, h, value); return ck_hs_put(&hs, h, value);
} }

@ -102,7 +102,7 @@ set_remove(const char *value)
{ {
unsigned long h; unsigned long h;
h = hs_hash(value, hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
ck_hs_remove(&hs, h, value); ck_hs_remove(&hs, h, value);
return true; return true;
} }
@ -113,7 +113,7 @@ set_replace(const char *value)
unsigned long h; unsigned long h;
void *previous; void *previous;
h = hs_hash(value, hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
ck_hs_set(&hs, h, value, &previous); ck_hs_set(&hs, h, value, &previous);
return previous != NULL; return previous != NULL;
} }
@ -124,7 +124,7 @@ set_get(const char *value)
unsigned long h; unsigned long h;
void *v; void *v;
h = hs_hash(value, hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
v = ck_hs_get(&hs, h, value); v = ck_hs_get(&hs, h, value);
return v; return v;
} }
@ -134,7 +134,7 @@ set_insert(const char *value)
{ {
unsigned long h; unsigned long h;
h = hs_hash(value, hs.seed); h = CK_HS_HASH(&hs, hs_hash, value);
return ck_hs_put(&hs, h, value); return ck_hs_put(&hs, h, value);
} }

Loading…
Cancel
Save