#endif
HASHKIT_API
-uint32_t hashkit_one_at_a_time(const char *key, size_t key_length);
+uint32_t libhashkit_one_at_a_time(const char *key, size_t key_length);
+
HASHKIT_API
-uint32_t hashkit_fnv1_64(const char *key, size_t key_length);
+uint32_t libhashkit_fnv1_64(const char *key, size_t key_length);
+
HASHKIT_API
-uint32_t hashkit_fnv1a_64(const char *key, size_t key_length);
+uint32_t libhashkit_fnv1a_64(const char *key, size_t key_length);
+
HASHKIT_API
-uint32_t hashkit_fnv1_32(const char *key, size_t key_length);
+uint32_t libhashkit_fnv1_32(const char *key, size_t key_length);
+
HASHKIT_API
-uint32_t hashkit_fnv1a_32(const char *key, size_t key_length);
+uint32_t libhashkit_fnv1a_32(const char *key, size_t key_length);
+
HASHKIT_API
-uint32_t hashkit_crc32(const char *key, size_t key_length);
+uint32_t libhashkit_crc32(const char *key, size_t key_length);
+
#ifdef HAVE_HSIEH_HASH
HASHKIT_API
-uint32_t hashkit_hsieh(const char *key, size_t key_length);
+uint32_t libhashkit_hsieh(const char *key, size_t key_length);
#endif
+
HASHKIT_API
-uint32_t hashkit_murmur(const char *key, size_t key_length);
+uint32_t libhashkit_murmur(const char *key, size_t key_length);
+
HASHKIT_API
-uint32_t hashkit_jenkins(const char *key, size_t key_length);
+uint32_t libhashkit_jenkins(const char *key, size_t key_length);
+
HASHKIT_API
-uint32_t hashkit_md5(const char *key, size_t key_length);
+uint32_t libhashkit_md5(const char *key, size_t key_length);
+
+HASHKIT_LOCAL
+uint32_t hashkit_one_at_a_time(const char *key, size_t key_length, void *context);
+
+HASHKIT_LOCAL
+uint32_t hashkit_fnv1_64(const char *key, size_t key_length, void *context);
+
+HASHKIT_LOCAL
+uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *context);
+
+HASHKIT_LOCAL
+uint32_t hashkit_fnv1_32(const char *key, size_t key_length, void *context);
+
+HASHKIT_LOCAL
+uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context);
+
+HASHKIT_LOCAL
+uint32_t hashkit_crc32(const char *key, size_t key_length, void *context);
+
+#ifdef HAVE_HSIEH_HASH
+HASHKIT_LOCAL
+uint32_t hashkit_hsieh(const char *key, size_t key_length, void *context);
+#endif
+
+HASHKIT_LOCAL
+uint32_t hashkit_murmur(const char *key, size_t key_length, void *context);
+
+HASHKIT_LOCAL
+uint32_t hashkit_jenkins(const char *key, size_t key_length, void *context);
+
+HASHKIT_LOCAL
+uint32_t hashkit_md5(const char *key, size_t key_length, void *context);
#ifdef __cplusplus
}
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
-uint32_t hashkit_crc32(const char *key, size_t key_length)
+uint32_t hashkit_crc32(const char *key, size_t key_length, void *context __attribute__((unused)))
{
uint64_t x;
uint32_t crc= UINT32_MAX;
static uint32_t FNV_32_INIT= 2166136261UL;
static uint32_t FNV_32_PRIME= 16777619;
-uint32_t hashkit_fnv1_64(const char *key, size_t key_length)
+uint32_t hashkit_fnv1_64(const char *key, size_t key_length, void *context __attribute__((unused)))
{
/* Thanks to pierre@demartines.com for the pointer */
uint64_t hash= FNV_64_INIT;
return (uint32_t)hash;
}
-uint32_t hashkit_fnv1a_64(const char *key, size_t key_length)
+uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *context __attribute__((unused)))
{
uint32_t hash= (uint32_t) FNV_64_INIT;
return hash;
}
-uint32_t hashkit_fnv1_32(const char *key, size_t key_length)
+uint32_t hashkit_fnv1_32(const char *key, size_t key_length, void *context __attribute__((unused)))
{
uint32_t hash= FNV_32_INIT;
return hash;
}
-uint32_t hashkit_fnv1a_32(const char *key, size_t key_length)
+uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context __attribute__((unused)))
{
uint32_t hash= FNV_32_INIT;
uint32_t hashkit_generate_value(const hashkit_st *self, const char *key, size_t key_length)
{
- return self->base_hash.function(key, key_length);
+ return self->base_hash.function(key, key_length, self->base_hash.context);
}
hashkit_return_t hashkit_set_base_function(hashkit_st *self, hashkit_hash_algorithm_t hash_algorithm)
switch (hash_algorithm)
{
case HASHKIT_HASH_DEFAULT:
- return hashkit_one_at_a_time(key, key_length);
+ return libhashkit_one_at_a_time(key, key_length);
case HASHKIT_HASH_MD5:
- return hashkit_md5(key, key_length);
+ return libhashkit_md5(key, key_length);
case HASHKIT_HASH_CRC:
- return hashkit_crc32(key, key_length);
+ return libhashkit_crc32(key, key_length);
case HASHKIT_HASH_FNV1_64:
- return hashkit_fnv1_64(key, key_length);
+ return libhashkit_fnv1_64(key, key_length);
case HASHKIT_HASH_FNV1A_64:
- return hashkit_fnv1a_64(key, key_length);
+ return libhashkit_fnv1a_64(key, key_length);
case HASHKIT_HASH_FNV1_32:
- return hashkit_fnv1_32(key, key_length);
+ return libhashkit_fnv1_32(key, key_length);
case HASHKIT_HASH_FNV1A_32:
- return hashkit_fnv1a_32(key, key_length);
+ return libhashkit_fnv1a_32(key, key_length);
case HASHKIT_HASH_HSIEH:
#ifdef HAVE_HSIEH_HASH
- return hashkit_hsieh(key, key_length);
+ return libhashkit_hsieh(key, key_length);
#else
return 1;
#endif
case HASHKIT_HASH_MURMUR:
- return hashkit_murmur(key, key_length);
+ return libhashkit_murmur(key, key_length);
case HASHKIT_HASH_JENKINS:
- return hashkit_jenkins(key, key_length);
+ return libhashkit_jenkins(key, key_length);
case HASHKIT_HASH_MAX:
default:
#ifdef HAVE_DEBUG
+(uint32_t)(((const uint8_t *)(d))[0]) )
#endif
-uint32_t hashkit_hsieh(const char *key, size_t key_length)
+uint32_t hashkit_hsieh(const char *key, size_t key_length, void *context__attribute__((unused)))
{
uint32_t hash = 0, tmp;
int rem;
libhashkit/common.h
libhashkit_libhashkit_la_SOURCES= \
- libhashkit/crc32.c \
+ libhashkit/algorithm.c \
libhashkit/behavior.c \
+ libhashkit/crc32.c \
libhashkit/fnv.c \
libhashkit/hashkit.c \
libhashkit/jenkins.c \
In which case, the hash table should have hashsize(10) elements.
*/
-uint32_t hashkit_jenkins(const char *key, size_t length)
+uint32_t hashkit_jenkins(const char *key, size_t length, void *context __attribute__((unused)))
{
uint32_t a,b,c; /* internal state */
union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
-uint32_t hashkit_md5(const char *key, size_t key_length)
+uint32_t hashkit_md5(const char *key, size_t key_length, void *context __attribute__((unused)))
{
unsigned char results[16];
#include "common.h"
-uint32_t hashkit_murmur(const char *key, size_t length)
+uint32_t hashkit_murmur(const char *key, size_t length, void *context __attribute__((unused)))
{
/*
'm' and 'r' are mixing constants generated offline. They're not
#include "common.h"
-uint32_t hashkit_one_at_a_time(const char *key, size_t key_length)
+uint32_t hashkit_one_at_a_time(const char *key, size_t key_length, void *context __attribute__((unused)))
{
const char *ptr= key;
uint32_t value= 0;
typedef struct hashkit_st hashkit_st;
-typedef uint32_t (*hashkit_hash_fn)(const char *key, size_t key_length);
+typedef uint32_t (*hashkit_hash_fn)(const char *key, size_t key_length, void *context);
#ifdef __cplusplus
}
{
uint32_t hash_val;
- hash_val= hashkit_one_at_a_time(*ptr, strlen(*ptr));
+ hash_val= libhashkit_one_at_a_time(*ptr, strlen(*ptr));
test_true(one_at_a_time_values[x] == hash_val);
}
{
uint32_t hash_val;
- hash_val= hashkit_md5(*ptr, strlen(*ptr));
+ hash_val= libhashkit_md5(*ptr, strlen(*ptr));
test_true(md5_values[x] == hash_val);
}
{
uint32_t hash_val;
- hash_val= hashkit_crc32(*ptr, strlen(*ptr));
+ hash_val= libhashkit_crc32(*ptr, strlen(*ptr));
assert(crc_values[x] == hash_val);
}
{
uint32_t hash_val;
- hash_val= hashkit_fnv1_64(*ptr, strlen(*ptr));
+ hash_val= libhashkit_fnv1_64(*ptr, strlen(*ptr));
assert(fnv1_64_values[x] == hash_val);
}
{
uint32_t hash_val;
- hash_val= hashkit_fnv1a_64(*ptr, strlen(*ptr));
+ hash_val= libhashkit_fnv1a_64(*ptr, strlen(*ptr));
assert(fnv1a_64_values[x] == hash_val);
}
{
uint32_t hash_val;
- hash_val= hashkit_fnv1_32(*ptr, strlen(*ptr));
+ hash_val= libhashkit_fnv1_32(*ptr, strlen(*ptr));
assert(fnv1_32_values[x] == hash_val);
}
{
uint32_t hash_val;
- hash_val= hashkit_fnv1a_32(*ptr, strlen(*ptr));
+ hash_val= libhashkit_fnv1a_32(*ptr, strlen(*ptr));
assert(fnv1a_32_values[x] == hash_val);
}
uint32_t hash_val;
#ifdef HAVE_HSIEH_HASH
- hash_val= hashkit_hsieh(*ptr, strlen(*ptr));
+ hash_val= libhashkit_hsieh(*ptr, strlen(*ptr));
#else
hash_val= 1;
#endif
{
uint32_t hash_val;
- hash_val= hashkit_murmur(*ptr, strlen(*ptr));
+ hash_val= libhashkit_murmur(*ptr, strlen(*ptr));
assert(murmur_values[x] == hash_val);
}
{
uint32_t hash_val;
- hash_val= hashkit_jenkins(*ptr, strlen(*ptr));
+ hash_val= libhashkit_jenkins(*ptr, strlen(*ptr));
assert(jenkins_values[x] == hash_val);
}
return TEST_SUCCESS;
}
+static uint32_t hash_test_function(const char *string, size_t string_length, void *context)
+{
+ (void)context;
+ return libhashkit_md5(string, string_length);
+}
+
static test_return_t hashkit_set_base_function_custom_test(hashkit_st *hashk)
{
hashkit_return_t rc;
const char **ptr;
- rc= hashkit_set_base_function_custom(hashk, hashkit_md5, NULL);
+ rc= hashkit_set_base_function_custom(hashk, hash_test_function, NULL);
test_true(rc == HASHKIT_SUCCESS);
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)