SETSOCKOPT_SANITY
ENABLE_HSIEH_HASH
ENABLE_MURMUR_HASH
+ENABLE_FNV64_HASH
ENABLE_MEMASLAP
PROTOCOL_BINARY_TEST
ENABLE_DEPRECATED
return hashkit_crc32(key, key_length, NULL);
}
-#ifdef HAVE_HSIEH_HASH
uint32_t libhashkit_hsieh(const char *key, size_t key_length)
{
return hashkit_hsieh(key, key_length, NULL);
}
-#endif
-#ifdef HAVE_MURMUR_HASH
uint32_t libhashkit_murmur(const char *key, size_t key_length)
{
return hashkit_murmur(key, key_length, NULL);
}
-#endif
uint32_t libhashkit_jenkins(const char *key, size_t key_length)
{
HASHKIT_API
uint32_t libhashkit_crc32(const char *key, size_t key_length);
-#ifdef HAVE_HSIEH_HASH
HASHKIT_API
uint32_t libhashkit_hsieh(const char *key, size_t key_length);
-#endif
-#ifdef HAVE_MURMUR_HASH
HASHKIT_API
uint32_t libhashkit_murmur(const char *key, size_t key_length);
-#endif
HASHKIT_API
uint32_t libhashkit_jenkins(const char *key, size_t key_length);
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
-#ifdef HAVE_MURMUR_HASH
HASHKIT_LOCAL
uint32_t hashkit_murmur(const char *key, size_t key_length, void *context);
-#endif
HASHKIT_LOCAL
uint32_t hashkit_jenkins(const char *key, size_t key_length, void *context);
#include <libhashkit/common.h>
+#if __WORDSIZE == 64 && defined(HAVE_FNV64_HASH)
+
/* FNV hash'es lifted from Dustin Sallings work */
static uint64_t FNV_64_INIT= 0xcbf29ce484222325;
static uint64_t FNV_64_PRIME= 0x100000001b3;
return hash;
}
+
+#else
+uint32_t hashkit_fnv1_64(const char *, size_t, void *)
+{
+ return 0;
+}
+
+uint32_t hashkit_fnv1a_64(const char *, size_t, void *)
+{
+ return 0;
+}
+#endif
static hashkit_return_t _set_function(struct hashkit_st::hashkit_function_st *self, hashkit_hash_algorithm_t hash_algorithm)
{
+ if (self == NULL)
+ {
+ return HASHKIT_INVALID_ARGUMENT;
+ }
+
switch (hash_algorithm)
{
- case HASHKIT_HASH_DEFAULT:
- self->function= hashkit_one_at_a_time;
- break;
case HASHKIT_HASH_MD5:
self->function= hashkit_md5;
break;
+
case HASHKIT_HASH_CRC:
self->function= hashkit_crc32;
break;
+
case HASHKIT_HASH_FNV1_64:
- self->function= hashkit_fnv1_64;
- break;
+ if (libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64))
+ {
+ self->function= hashkit_fnv1_64;
+ break;
+ }
+ return HASHKIT_INVALID_ARGUMENT;
+
case HASHKIT_HASH_FNV1A_64:
- self->function= hashkit_fnv1a_64;
- break;
+ if (libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64))
+ {
+ self->function= hashkit_fnv1a_64;
+ break;
+ }
+ return HASHKIT_INVALID_ARGUMENT;
+
case HASHKIT_HASH_FNV1_32:
self->function= hashkit_fnv1_32;
break;
+
case HASHKIT_HASH_FNV1A_32:
self->function= hashkit_fnv1a_32;
break;
+
case HASHKIT_HASH_HSIEH:
-#ifdef HAVE_HSIEH_HASH
- self->function= hashkit_hsieh;
- break;
-#else
- return HASHKIT_FAILURE;
-#endif
+ if (libhashkit_has_algorithm(HASHKIT_HASH_HSIEH))
+ {
+ self->function= hashkit_hsieh;
+ break;
+ }
+ return HASHKIT_INVALID_ARGUMENT;
+
case HASHKIT_HASH_MURMUR:
-#ifdef HAVE_MURMUR_HASH
- self->function= hashkit_murmur;
- break;
-#else
- return HASHKIT_FAILURE;
-#endif
+ if (libhashkit_has_algorithm(HASHKIT_HASH_MURMUR))
+ {
+ self->function= hashkit_murmur;
+ break;
+ }
+ return HASHKIT_INVALID_ARGUMENT;
+
case HASHKIT_HASH_JENKINS:
self->function= hashkit_jenkins;
break;
+
case HASHKIT_HASH_CUSTOM:
return HASHKIT_INVALID_ARGUMENT;
+
+ case HASHKIT_HASH_DEFAULT:
+ self->function= hashkit_one_at_a_time;
+ break;
+
case HASHKIT_HASH_MAX:
- default:
+ self->function= hashkit_one_at_a_time;
return HASHKIT_INVALID_HASH;
}
static hashkit_return_t _set_custom_function(struct hashkit_st::hashkit_function_st *self, hashkit_hash_fn function, void *context)
{
+ if (self == NULL)
+ {
+ return HASHKIT_INVALID_ARGUMENT;
+ }
+
if (function)
{
self->function= function;
hashkit_return_t hashkit_set_custom_function(hashkit_st *self, hashkit_hash_fn function, void *context)
{
+ if (self == NULL)
+ {
+ return HASHKIT_INVALID_ARGUMENT;
+ }
+
+
return _set_custom_function(&self->base_hash, function, context);
}
hashkit_return_t hashkit_set_custom_distribution_function(hashkit_st *self, hashkit_hash_fn function, void *context)
{
+ if (self == NULL)
+ {
+ return HASHKIT_INVALID_ARGUMENT;
+ }
+
return _set_custom_function(&self->distribution_hash, function, context);
}
{
return HASHKIT_HASH_FNV1A_32;
}
-#ifdef HAVE_HSIEH_HASH
else if (function == hashkit_hsieh)
{
return HASHKIT_HASH_HSIEH;
}
-#endif
-#ifdef HAVE_MURMUR_HASH
else if (function == hashkit_murmur)
{
return HASHKIT_HASH_MURMUR;
}
-#endif
else if (function == hashkit_jenkins)
{
return HASHKIT_HASH_JENKINS;
hashkit_hash_algorithm_t hashkit_get_function(const hashkit_st *self)
{
+ if (self == NULL)
+ {
+ return HASHKIT_HASH_DEFAULT;
+ }
+
return get_function_type(self->base_hash.function);
}
hashkit_hash_algorithm_t hashkit_get_distribution_function(const hashkit_st *self)
{
+ if (self == NULL)
+ {
+ return HASHKIT_HASH_DEFAULT;
+ }
+
return get_function_type(self->distribution_hash.function);
}
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <libhashkit/common.h>
+
+bool libhashkit_has_algorithm(const hashkit_hash_algorithm_t algo)
+{
+ switch (algo)
+ {
+ case HASHKIT_HASH_FNV1_64:
+ case HASHKIT_HASH_FNV1A_64:
+#if __WORDSIZE == 64 && defined(HAVE_FNV64_HASH)
+ return true;
+#else
+ return false;
+#endif
+
+ case HASHKIT_HASH_HSIEH:
+#ifdef HAVE_HSIEH_HASH
+ return true;
+#else
+ return false;
+#endif
+
+ case HASHKIT_HASH_MURMUR:
+#ifdef HAVE_MURMUR_HASH
+ return true;
+#else
+ return false;
+#endif
+
+ case HASHKIT_HASH_FNV1_32:
+ case HASHKIT_HASH_FNV1A_32:
+ case HASHKIT_HASH_DEFAULT:
+ case HASHKIT_HASH_MD5:
+ case HASHKIT_HASH_CRC:
+ case HASHKIT_HASH_JENKINS:
+ case HASHKIT_HASH_CUSTOM:
+ return true;
+
+ case HASHKIT_HASH_MAX:
+ break;
+ }
+
+ return false;
+}
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Libmemcached library
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+HASHKIT_API
+bool libhashkit_has_algorithm(const hashkit_hash_algorithm_t);
+
+#ifdef __cplusplus
+}
+#endif
#include <libhashkit/visibility.h>
#include <libhashkit/configure.h>
#include <libhashkit/types.h>
+#include <libhashkit/has.h>
#include <libhashkit/algorithm.h>
#include <libhashkit/behavior.h>
#include <libhashkit/digest.h>
+(uint32_t)(((const uint8_t *)(d))[0]) )
#endif
-uint32_t hashkit_hsieh(const char *key, size_t key_length, void *context __attribute__((unused)))
+#ifdef HAVE_HSIEH_HASH
+uint32_t hashkit_hsieh(const char *key, size_t key_length, void *)
{
uint32_t hash = 0, tmp;
int rem;
return hash;
}
-
+#else
+uint32_t hashkit_hsieh(const char *, size_t , void *)
+{
+ return 0;
+}
+#endif
libhashkit/configure.h \
libhashkit/digest.h \
libhashkit/function.h \
+ libhashkit/has.h \
libhashkit/hashkit.h \
libhashkit/hashkit.hpp \
libhashkit/strerror.h \
libhashkit/fnv_32.cc \
libhashkit/fnv_64.cc \
libhashkit/function.cc \
+ libhashkit/has.cc \
libhashkit/hashkit.cc \
+ libhashkit/hsieh.cc \
libhashkit/jenkins.cc \
libhashkit/ketama.cc \
libhashkit/md5.cc \
+ libhashkit/murmur.cc \
libhashkit/one_at_a_time.cc \
libhashkit/str_algorithm.cc \
libhashkit/strerror.cc
-if INCLUDE_HSIEH_SRC
-libhashkit_libhashkit_la_SOURCES+= libhashkit/hsieh.cc
-endif
-if INCLUDE_MURMUR_SRC
-libhashkit_libhashkit_la_SOURCES+= libhashkit/murmur.cc
-endif
libhashkit_libhashkit_la_CPPFLAGS= -DBUILDING_HASHKIT
#include <libhashkit/common.h>
+#ifdef HAVE_MURMUR_HASH
+
uint32_t hashkit_murmur(const char *key, size_t length, void *context)
{
/*
return h;
}
+
+#else
+uint32_t hashkit_murmur(const char *, size_t , void *)
+{
+ return 0;
+}
+#endif
HASHKIT_MAXIMUM_RETURN /* Always add new error code before */
} hashkit_return_t;
-#define hashkit_success(X) ((X) == HASHKIT_SUCCESS)
-#define hashkit_failed(X) ((X) != HASHKIT_SUCCESS)
+static inline bool hashkit_success(const hashkit_return_t rc)
+{
+ return (rc == HASHKIT_SUCCESS);
+}
+
+static inline bool hashkit_failed(const hashkit_return_t rc)
+{
+ return (rc != HASHKIT_SUCCESS);
+}
typedef enum {
HASHKIT_HASH_DEFAULT= 0, // hashkit_one_at_a_time()
memcached_return_t memcached_behavior_set_key_hash(memcached_st *ptr, memcached_hash_t type)
{
if (hashkit_success(hashkit_set_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type)))
+ {
return MEMCACHED_SUCCESS;
+ }
return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
memcached_literal_param("Invalid memcached_hash_t()"));
--- /dev/null
+dnl ---------------------------------------------------------------------------
+dnl Macro: ENABLE_FNV64_HASH
+dnl ---------------------------------------------------------------------------
+AC_DEFUN([ENABLE_FNV64_HASH],
+ [AC_ARG_ENABLE([fnv64_hash],
+ [AS_HELP_STRING([--disable-fnv64_hash],
+ [build with support for fnv64 hashing. @<:@default=on@:>@])],
+ [ac_cv_enable_fnv64_hash=no],
+ [ac_cv_enable_fnv64_hash=yes])
+
+ AS_IF([test "$ac_cv_enable_fnv64_hash" = "yes"],
+ [AC_DEFINE([HAVE_FNV64_HASH], [1], [Enables fnv64 hashing support])])
+])
+dnl ---------------------------------------------------------------------------
+dnl End Macro: ENABLE_FNV64_HASH
+dnl ---------------------------------------------------------------------------
%{_includedir}/libhashkit/configure.h
%{_includedir}/libhashkit/digest.h
%{_includedir}/libhashkit/function.h
+%{_includedir}/libhashkit/has.h
%{_includedir}/libhashkit/hashkit.h
%{_includedir}/libhashkit/hashkit.hpp
%{_includedir}/libhashkit/str_algorithm.h
#include "hash_results.h"
-static test_return_t exists_test(void *obj)
+static test_return_t exists_test(void *)
{
Hashkit hashk;
- (void)obj;
(void)hashk;
return TEST_SUCCESS;
}
-static test_return_t new_test(void *obj)
+static test_return_t new_test(void *)
{
Hashkit *hashk= new Hashkit;
- (void)obj;
(void)hashk;
return TEST_SUCCESS;
}
-static test_return_t copy_test(void *obj)
+static test_return_t copy_test(void *)
{
Hashkit *hashk= new Hashkit;
Hashkit *copy(hashk);
- (void)obj;
(void)copy;
return TEST_SUCCESS;
}
-static test_return_t assign_test(void *obj)
+static test_return_t assign_test(void *)
{
Hashkit hashk;
Hashkit copy;
- (void)obj;
copy= hashk;
{
hashkit_return_t rc= hashk.set_function(*algo);
+ if (rc == HASHKIT_INVALID_ARGUMENT)
+ {
+ continue;
+ }
+
test_compare(HASHKIT_SUCCESS, rc);
uint32_t *list;
break;
case HASHKIT_HASH_HSIEH:
-#ifndef HAVE_HSIEH_HASH
- continue;
-#endif
list= hsieh_values;
break;
case HASHKIT_HASH_MURMUR:
#ifdef WORDS_BIGENDIAN
continue;
-#endif
-#ifndef HAVE_MURMUR_HASH
- continue;
#endif
list= murmur_values;
break;
return TEST_SUCCESS;
}
-static test_return_t set_distribution_function_test(void *obj)
+static test_return_t set_distribution_function_test(void *)
{
Hashkit hashk;
hashkit_return_t rc;
- (void)obj;
rc= hashk.set_distribution_function(HASHKIT_HASH_CUSTOM);
test_true_got(rc == HASHKIT_FAILURE or rc == HASHKIT_INVALID_ARGUMENT, hashkit_strerror(NULL, rc));
- rc= hashk.set_distribution_function(HASHKIT_HASH_JENKINS);
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS,
+ hashk.set_distribution_function(HASHKIT_HASH_JENKINS));
return TEST_SUCCESS;
}
-static test_return_t compare_function_test(void *obj)
+static test_return_t compare_function_test(void *)
{
Hashkit a, b;
- (void)obj;
b= a;
bool _unused;
};
-static test_return_t init_test(void *not_used)
+static test_return_t init_test(void *)
{
hashkit_st hashk;
hashkit_st *hashk_ptr;
- (void)not_used;
hashk_ptr= hashkit_create(&hashk);
test_true(hashk_ptr);
test_true(hashk_ptr == &hashk);
- test_true(hashkit_is_allocated(hashk_ptr) == false);
+ test_false(hashkit_is_allocated(hashk_ptr));
hashkit_free(hashk_ptr);
return TEST_SUCCESS;
}
-static test_return_t allocation_test(void *not_used)
+static test_return_t allocation_test(void *)
{
hashkit_st *hashk_ptr;
- (void)not_used;
hashk_ptr= hashkit_create(NULL);
test_true(hashk_ptr);
- test_true(hashkit_is_allocated(hashk_ptr) == true);
+ test_true(hashkit_is_allocated(hashk_ptr));
hashkit_free(hashk_ptr);
return TEST_SUCCESS;
static test_return_t clone_test(hashkit_st *hashk)
{
// First we make sure that the testing system is giving us what we expect.
- assert(&global_hashk == hashk);
+ test_true(&global_hashk == hashk);
// Second we test if hashk is even valid
return TEST_SUCCESS;
}
-static test_return_t one_at_a_time_run (hashkit_st *hashk)
+static test_return_t one_at_a_time_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_one_at_a_time(*ptr, strlen(*ptr));
- test_true(one_at_a_time_values[x] == hash_val);
+ test_compare(one_at_a_time_values[x],
+ libhashkit_one_at_a_time(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t md5_run (hashkit_st *hashk)
+static test_return_t md5_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_md5(*ptr, strlen(*ptr));
- test_true(md5_values[x] == hash_val);
+ test_compare(md5_values[x],
+ libhashkit_md5(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t crc_run (hashkit_st *hashk)
+static test_return_t crc_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_crc32(*ptr, strlen(*ptr));
- test_compare(crc_values[x], hash_val);
+ test_compare(crc_values[x],
+ libhashkit_crc32(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1_64_run (hashkit_st *hashk)
+static test_return_t fnv1_64_run (hashkit_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64));
+
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1_64(*ptr, strlen(*ptr));
- test_compare(fnv1_64_values[x], hash_val);
+ test_compare(fnv1_64_values[x],
+ libhashkit_fnv1_64(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1a_64_run (hashkit_st *hashk)
+static test_return_t fnv1a_64_run (hashkit_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1A_64));
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1a_64(*ptr, strlen(*ptr));
- test_compare(fnv1a_64_values[x], hash_val);
+ test_compare(fnv1a_64_values[x],
+ libhashkit_fnv1a_64(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1_32_run (hashkit_st *hashk)
+static test_return_t fnv1_32_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1_32(*ptr, strlen(*ptr));
- test_compare(fnv1_32_values[x], hash_val);
+ test_compare(fnv1_32_values[x],
+ libhashkit_fnv1_32(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1a_32_run (hashkit_st *hashk)
+static test_return_t fnv1a_32_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1a_32(*ptr, strlen(*ptr));
- test_compare(fnv1a_32_values[x], hash_val);
+ test_compare(fnv1a_32_values[x],
+ libhashkit_fnv1a_32(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t hsieh_run (hashkit_st *hashk)
+static test_return_t hsieh_run (hashkit_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH));
+
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
-#ifdef HAVE_HSIEH_HASH
- hash_val= libhashkit_hsieh(*ptr, strlen(*ptr));
-#else
- hash_val= 1;
-#endif
- test_compare(hsieh_values[x], hash_val);
+ test_compare(hsieh_values[x],
+ libhashkit_hsieh(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t murmur_run (hashkit_st *hashk)
+static test_return_t murmur_run (hashkit_st *)
{
- (void)hashk;
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR));
#ifdef WORDS_BIGENDIAN
(void)murmur_values;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
-#ifdef HAVE_MURMUR_HASH
- hash_val= libhashkit_murmur(*ptr, strlen(*ptr));
-#else
- hash_val= 1;
-#endif
- test_compare(murmur_values[x], hash_val);
+ test_compare(murmur_values[x],
+ libhashkit_murmur(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
#endif
}
-static test_return_t jenkins_run (hashkit_st *hashk)
+static test_return_t jenkins_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_jenkins(*ptr, strlen(*ptr));
- test_compare(jenkins_values[x], hash_val);
+ test_compare(jenkins_values[x],
+ libhashkit_jenkins(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
const char **ptr;
uint32_t *list;
- hashkit_return_t rc= hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
+ test_skip(true, libhashkit_has_algorithm(static_cast<hashkit_hash_algorithm_t>(algo)));
- /* Hsieh is disabled most of the time for patent issues */
-#ifndef HAVE_HSIEH_HASH
- if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
- continue;
-#endif
-
-#ifndef HAVE_MURMUR_HASH
- if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_MURMUR)
- continue;
-#endif
-
- if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM)
- continue;
+ hashkit_return_t rc= hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
- test_true_got(rc == HASHKIT_SUCCESS, hashkit_strerror(NULL, rc));
+ test_compare_got(HASHKIT_SUCCESS, rc, hashkit_strerror(NULL, rc));
switch (algo)
{
case HASHKIT_HASH_DEFAULT:
list= one_at_a_time_values;
break;
+
case HASHKIT_HASH_MD5:
list= md5_values;
break;
+
case HASHKIT_HASH_CRC:
list= crc_values;
break;
+
case HASHKIT_HASH_FNV1_64:
list= fnv1_64_values;
break;
+
case HASHKIT_HASH_FNV1A_64:
list= fnv1a_64_values;
break;
+
case HASHKIT_HASH_FNV1_32:
list= fnv1_32_values;
break;
+
case HASHKIT_HASH_FNV1A_32:
list= fnv1a_32_values;
break;
+
case HASHKIT_HASH_HSIEH:
list= hsieh_values;
break;
+
case HASHKIT_HASH_MURMUR:
list= murmur_values;
break;
+
case HASHKIT_HASH_JENKINS:
list= jenkins_values;
break;
+
case HASHKIT_HASH_CUSTOM:
case HASHKIT_HASH_MAX:
default:
{
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
- test_true(list[x] == hash_val);
+ test_compare(list[x],
+ hashkit_digest(hashk, *ptr, strlen(*ptr)));
}
}
else
return TEST_SUCCESS;
}
-static uint32_t hash_test_function(const char *string, size_t string_length, void *context)
+static uint32_t hash_test_function(const char *string, size_t string_length, void *)
{
- (void)context;
return libhashkit_md5(string, string_length);
}
static test_return_t hashkit_set_custom_function_test(hashkit_st *hashk)
{
- hashkit_return_t rc;
uint32_t x;
const char **ptr;
- rc= hashkit_set_custom_function(hashk, hash_test_function, NULL);
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS,
+ hashkit_set_custom_function(hashk, hash_test_function, NULL));
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
- test_true(md5_values[x] == hash_val);
+ test_compare(md5_values[x],
+ hashkit_digest(hashk, *ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
hashkit_return_t rc= hashkit_set_distribution_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
/* Hsieh is disabled most of the time for patent issues */
- if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
- continue;
-
- if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM)
+ if (rc == HASHKIT_INVALID_ARGUMENT)
continue;
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS, rc);
}
return TEST_SUCCESS;
static test_return_t hashkit_set_custom_distribution_function_test(hashkit_st *hashk)
{
- hashkit_return_t rc= hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL);
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS,
+ hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL));
return TEST_SUCCESS;
}
for (int algo= int(HASHKIT_HASH_DEFAULT); algo < int(HASHKIT_HASH_MAX); algo++)
{
- if (HASHKIT_HASH_CUSTOM or HASHKIT_HASH_HSIEH)
+ if (HASHKIT_HASH_CUSTOM)
+ {
continue;
+ }
+ test_skip(true, libhashkit_has_algorithm(static_cast<hashkit_hash_algorithm_t>(algo)));
- hashkit_return_t rc= hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS,
+ hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo)));
- test_true(hashkit_get_function(hashk) == algo);
+ test_compare(hashkit_get_function(hashk), algo);
}
return TEST_SUCCESS;
}
{0, 0, 0}
};
-static test_return_t libhashkit_digest_test(hashkit_st *hashk)
+static test_return_t libhashkit_digest_test(hashkit_st *)
{
-
- (void)hashk;
-
- uint32_t value= libhashkit_digest("a", sizeof("a"), HASHKIT_HASH_DEFAULT);
- test_true(value);
+ test_true(libhashkit_digest("a", sizeof("a"), HASHKIT_HASH_DEFAULT));
return TEST_SUCCESS;
}
static test_return_t pre_murmur(memcached_st *memc)
{
-#ifdef HAVE_MURMUR_HASH
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR);
+ test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR));
return TEST_SUCCESS;
-#else
- (void) memc;
- return TEST_SKIPPED;
-#endif
}
static test_return_t pre_jenkins(memcached_st *memc)
static test_return_t pre_hsieh(memcached_st *memc)
{
-#ifdef HAVE_HSIEH_HASH
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH);
+ test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH));
return TEST_SUCCESS;
-#else
- (void) memc;
- return TEST_SKIPPED;
-#endif
}
static test_return_t pre_hash_fnv1_64(memcached_st *memc)
{
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR);
+ test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR));
return TEST_SUCCESS;
}
static test_return_t pre_hash_fnv1a_64(memcached_st *memc)
{
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_64);
+ test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_64));
return TEST_SUCCESS;
}
static test_return_t hsieh_avaibility_test (memcached_st *memc)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH));
+
memcached_return_t expected_rc= MEMCACHED_INVALID_ARGUMENTS;
#ifdef HAVE_HSIEH_HASH
expected_rc= MEMCACHED_SUCCESS;
#endif
memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH,
(uint64_t)MEMCACHED_HASH_HSIEH);
- test_true(rc == expected_rc);
+ test_compare(expected_rc, rc);
return TEST_SUCCESS;
}
static test_return_t murmur_avaibility_test (memcached_st *memc)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR));
+
memcached_return_t expected_rc= MEMCACHED_INVALID_ARGUMENTS;
#ifdef HAVE_MURMUR_HASH
expected_rc= MEMCACHED_SUCCESS;
#endif
memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH,
(uint64_t)MEMCACHED_HASH_MURMUR);
- test_true(rc == expected_rc);
+ test_compare(expected_rc, rc);
return TEST_SUCCESS;
}
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_DEFAULT);
- test_true(one_at_a_time_values[x] == hash_val);
+ test_compare(one_at_a_time_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_DEFAULT));
}
return TEST_SUCCESS;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MD5);
- test_true(md5_values[x] == hash_val);
+ test_compare(md5_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MD5));
}
return TEST_SUCCESS;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_CRC);
- test_true(crc_values[x] == hash_val);
+ test_compare(crc_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_CRC));
}
return TEST_SUCCESS;
static test_return_t fnv1_64_run (memcached_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64));
+
uint32_t x;
const char **ptr;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_64);
- test_true(fnv1_64_values[x] == hash_val);
+ test_compare(fnv1_64_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_64));
}
return TEST_SUCCESS;
static test_return_t fnv1a_64_run (memcached_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1A_64));
+
uint32_t x;
const char **ptr;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_64);
- test_true(fnv1a_64_values[x] == hash_val);
+ test_compare(fnv1a_64_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_64));
}
return TEST_SUCCESS;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_32);
- test_true(fnv1_32_values[x] == hash_val);
+ test_compare(fnv1_32_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_32));
}
return TEST_SUCCESS;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_32);
- test_true(fnv1a_32_values[x] == hash_val);
+ test_compare(fnv1a_32_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_32));
}
return TEST_SUCCESS;
static test_return_t hsieh_run (memcached_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH));
+
uint32_t x;
const char **ptr;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_HSIEH);
- test_true(hsieh_values[x] == hash_val);
+ test_compare(hsieh_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_HSIEH));
}
return TEST_SUCCESS;
static test_return_t murmur_run (memcached_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR));
+
#ifdef WORDS_BIGENDIAN
(void)murmur_values;
return TEST_SKIPPED;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MURMUR);
- test_true(murmur_values[x] == hash_val);
+ test_compare(murmur_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MURMUR));
}
return TEST_SUCCESS;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_JENKINS);
- test_true(jenkins_values[x] == hash_val);
+ test_compare(jenkins_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_JENKINS));
}
return TEST_SUCCESS;
}
-static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *context)
+static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *)
{
- (void)context;
return libhashkit_md5(string, string_length);
}
-static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *context)
+static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *)
{
- (void)context;
return libhashkit_crc32(string, string_length);
}
scanner_variable_t hash_strings[]= {
{ ARRAY, make_scanner_string("--HASH=CRC"), scanner_string_null, NULL },
{ ARRAY, make_scanner_string("--HASH=FNV1A_32"), scanner_string_null, NULL },
- { ARRAY, make_scanner_string("--HASH=FNV1A_64"), scanner_string_null, NULL },
{ ARRAY, make_scanner_string("--HASH=FNV1_32"), scanner_string_null, NULL },
- { ARRAY, make_scanner_string("--HASH=FNV1_64"), scanner_string_null, NULL },
{ ARRAY, make_scanner_string("--HASH=JENKINS"), scanner_string_null, NULL },
{ ARRAY, make_scanner_string("--HASH=MD5"), scanner_string_null, NULL },
- { ARRAY, make_scanner_string("--HASH=MURMUR"), scanner_string_null, NULL },
{ NIL, scanner_string_null, scanner_string_null, NULL}
};