* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
uint32_t libhashkit_one_at_a_time(const char *key, size_t key_length)
{
* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
#ifndef HASHKIT_COMMON_H
#define HASHKIT_COMMON_H
-#include "config.h"
+#include <config.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <math.h>
-#include "hashkit.h"
+#include <libhashkit/hashkit.h>
#ifdef __cplusplus
extern "C" {
* src/usr.bin/cksum/crc32.c.
*/
-#include "common.h"
+#include <libhashkit/common.h>
static const uint32_t crc32tab[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
uint32_t hashkit_digest(const hashkit_st *self, const char *key, size_t key_length)
{
* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
/* FNV hash'es lifted from Dustin Sallings work */
static uint64_t FNV_64_INIT= UINT64_C(0xcbf29ce484222325);
* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
static hashkit_return_t _set_function(struct hashkit_function_st *self, hashkit_hash_algorithm_t hash_algorithm)
{
* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
static const hashkit_st global_default_hash= {
.base_hash= {
#include <libhashkit/behavior.h>
#include <libhashkit/digest.h>
#include <libhashkit/function.h>
+#include <libhashkit/str_algorithm.h>
#include <libhashkit/strerror.h>
#ifdef __cplusplus
-
-#include <string>
-
extern "C" {
#endif
};
#ifdef __cplusplus
-class Hashkit : private hashkit_st {
+
+#include <string>
+
+class Hashkit {
public:
Hashkit()
{
- hashkit_create(this);
+ hashkit_create(&self);
}
Hashkit(const Hashkit& source)
{
- hashkit_clone(this, &source);
+ hashkit_clone(&self, &source.self);
}
Hashkit& operator=(const Hashkit& source)
{
- hashkit_free(this);
- hashkit_clone(this, &source);
+ hashkit_free(&self);
+ hashkit_clone(&self, &source.self);
return *this;
}
friend bool operator==(const Hashkit &left, const Hashkit &right)
{
- return hashkit_compare(&left, &right);
+ return hashkit_compare(&left.self, &right.self);
}
uint32_t digest(std::string& str)
{
- return hashkit_digest(this, str.c_str(), str.length());
+ return hashkit_digest(&self, str.c_str(), str.length());
}
uint32_t digest(const char *key, size_t key_length)
{
- return hashkit_digest(this, key, key_length);
+ return hashkit_digest(&self, key, key_length);
}
hashkit_return_t set_function(hashkit_hash_algorithm_t hash_algorithm)
{
- return hashkit_set_function(this, hash_algorithm);
+ return hashkit_set_function(&self, hash_algorithm);
}
hashkit_return_t set_distribution_function(hashkit_hash_algorithm_t hash_algorithm)
{
- return hashkit_set_function(this, hash_algorithm);
+ return hashkit_set_function(&self, hash_algorithm);
}
~Hashkit()
{
- hashkit_free(this);
+ hashkit_free(&self);
}
+private:
+
+ hashkit_st self;
};
#endif
* http://www.azillionmonkeys.com/qed/hash.html
*/
-#include "common.h"
+#include <libhashkit/common.h>
#undef get16bits
#if (defined(__GNUC__) && defined(__i386__))
libhashkit/function.h \
libhashkit/hashkit.h \
libhashkit/strerror.h \
+ libhashkit/str_algorithm.h \
libhashkit/types.h \
libhashkit/visibility.h
libhashkit/algorithm.c \
libhashkit/behavior.c \
libhashkit/crc32.c \
- libhashkit/fnv.c \
libhashkit/digest.c \
+ libhashkit/fnv.c \
libhashkit/function.c \
libhashkit/hashkit.c \
libhashkit/jenkins.c \
libhashkit/ketama.c \
libhashkit/md5.c \
libhashkit/one_at_a_time.c \
+ libhashkit/str_algorithm.c \
libhashkit/strerror.c
if INCLUDE_HSIEH_SRC
* Add big endian support
*/
-#include "common.h"
+#include <libhashkit/common.h>
#define hashsize(n) ((uint32_t)1<<(n))
#define hashmask(n) (hashsize(n)-1)
* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
#include <math.h>
#if 0
documentation and/or software.
*/
-#include "common.h"
+#include <libhashkit/common.h>
#include <string.h>
#include <sys/types.h>
Updated to murmur2 hash - BP
*/
-#include "common.h"
+#include <libhashkit/common.h>
uint32_t hashkit_murmur(const char *key, size_t length, void *context)
{
http://en.wikipedia.org/wiki/Jenkins_hash_function
*/
-#include "common.h"
+#include <libhashkit/common.h>
uint32_t hashkit_one_at_a_time(const char *key, size_t key_length, void *context)
{
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * HashKit
+ *
+ * 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>
+
+const char * libhashkit_string_hash(hashkit_hash_algorithm_t type)
+{
+ switch(type)
+ {
+ case HASHKIT_HASH_DEFAULT: return "DEFAULT";
+ case HASHKIT_HASH_MD5: return "MD5";
+ case HASHKIT_HASH_CRC: return "CRC";
+ case HASHKIT_HASH_FNV1_64: return "FNV1_64";
+ case HASHKIT_HASH_FNV1A_64: return "FNV1A_64";
+ case HASHKIT_HASH_FNV1_32: return "FNV1_32";
+ case HASHKIT_HASH_FNV1A_32: return "FNV1A_32";
+ case HASHKIT_HASH_HSIEH: return "HSIEH";
+ case HASHKIT_HASH_MURMUR: return "MURMUR";
+ case HASHKIT_HASH_JENKINS: return "JENKINS";
+ case HASHKIT_HASH_CUSTOM: return "CUSTOM";
+ default:
+ case HASHKIT_HASH_MAX: return "INVALID";
+ }
+}
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * HashKit
+ *
+ * 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
+const char *libhashkit_string_hash(hashkit_hash_algorithm_t type);
+
+#ifdef __cplusplus
+}
+#endif
* the COPYING file in the parent directory for full text.
*/
-#include "common.h"
+#include <libhashkit/common.h>
const char *hashkit_strerror(hashkit_st *ptr, hashkit_return_t rc)
{
-
-/* HashKit
- * Copyright (C) 2009 Brian Aker
- * All rights reserved.
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * HashKit
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2009 Brian Aker All rights reserved.
+ *
+ * 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.
*
- * Use and distribution licensed under the BSD license. See
- * the COPYING file in the parent directory for full text.
*/
+
#ifndef HASHKIT_TYPES_H
#define HASHKIT_TYPES_H
const char * libmemcached_string_hash(memcached_hash_t type)
{
- switch (type)
- {
- case MEMCACHED_HASH_DEFAULT: return "MEMCACHED_HASH_DEFAULT";
- case MEMCACHED_HASH_MD5: return "MEMCACHED_HASH_MD5";
- case MEMCACHED_HASH_CRC: return "MEMCACHED_HASH_CRC";
- case MEMCACHED_HASH_FNV1_64: return "MEMCACHED_HASH_FNV1_64";
- case MEMCACHED_HASH_FNV1A_64: return "MEMCACHED_HASH_FNV1A_64";
- case MEMCACHED_HASH_FNV1_32: return "MEMCACHED_HASH_FNV1_32";
- case MEMCACHED_HASH_FNV1A_32: return "MEMCACHED_HASH_FNV1A_32";
- case MEMCACHED_HASH_HSIEH: return "MEMCACHED_HASH_HSIEH";
- case MEMCACHED_HASH_MURMUR: return "MEMCACHED_HASH_MURMUR";
- case MEMCACHED_HASH_JENKINS: return "MEMCACHED_HASH_JENKINS";
- case MEMCACHED_HASH_CUSTOM: return "MEMCACHED_HASH_CUSTOM";
- default:
- case MEMCACHED_HASH_MAX: return "INVALID memcached_hash_t";
- }
+ return libhashkit_string_hash((hashkit_hash_algorithm_t)type);
}
} // extern "C"
#endif
-
-#ifdef __cplusplus
-class Memcached : private memcached_st {
-public:
-
- Memcached()
- {
- memcached_create(this);
- }
-
- ~Memcached()
- {
- memcached_free(this);
- }
-
- Memcached(const Memcached& source)
- {
- memcached_clone(this, &source);
- }
-
- Memcached& operator=(const Memcached& source)
- {
- memcached_free(this);
- memcached_clone(this, &source);
-
- return *this;
- }
-};
-#endif
-
#endif /* __LIBMEMCACHED_MEMCACHED_H__ */
*/
#include <libtest/test.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include <libhashkit/hashkit.h>
return TEST_SUCCESS;
}
-static test_return_t set_function_test(void *obj)
+static test_return_t set_function_test(void *)
{
Hashkit hashk;
hashkit_hash_algorithm_t algo_list[]= {
HASHKIT_HASH_JENKINS,
HASHKIT_HASH_MAX
};
- hashkit_hash_algorithm_t *algo;
- (void)obj;
- for (algo= algo_list; *algo != HASHKIT_HASH_MAX; algo++)
+ for (hashkit_hash_algorithm_t *algo= algo_list; *algo != HASHKIT_HASH_MAX; algo++)
{
- hashkit_return_t rc;
- uint32_t x;
- const char **ptr;
- uint32_t *list;
-
- rc= hashk.set_function(*algo);
+ hashkit_return_t rc= hashk.set_function(*algo);
test_true(rc == HASHKIT_SUCCESS);
+ uint32_t *list;
switch (*algo)
{
case HASHKIT_HASH_DEFAULT:
list= fnv1a_32_values;
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;
case HASHKIT_HASH_JENKINS:
}
// Now we make sure we did set the hash correctly.
+ uint32_t x;
+ const char **ptr;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
uint32_t hash_val;
hash_val= hashk.digest(*ptr, strlen(*ptr));
- test_true(list[x] == hash_val);
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "%lu %lus %s", (unsigned long)list[x], (unsigned long)hash_val, libhashkit_string_hash(*algo));
+ test_true_got(list[x] == hash_val, buffer);
}
}
(void)obj;
rc= hashk.set_distribution_function(HASHKIT_HASH_CUSTOM);
- test_true(rc == HASHKIT_FAILURE);
+ 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);
noinst_PROGRAMS+= \
tests/atomsmasher \
- tests/hashplus \
- tests/memplus \
+ tests/hash_plus \
tests/startservers \
tests/testapp \
tests/testhashkit \
tests_testhashkit_DEPENDENCIES = libtest/libtest.la libhashkit/libhashkit.la
tests_testhashkit_LDADD = $(tests_testhashkit_DEPENDENCIES) $(LIBSASL)
-tests_hashplus_SOURCES = tests/hash_plus.cc
-tests_hashplus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX)
-tests_hashplus_DEPENDENCIES = $(tests_testhashkit_DEPENDENCIES)
-tests_hashplus_LDADD = $(tests_testhashkit_DEPENDENCIES) $(LIBSASL)
-
-tests_memplus_SOURCES = tests/mem_plus.cc
-tests_memplus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX)
-tests_memplus_DEPENDENCIES = $(TESTS_LDADDS)
-tests_memplus_LDADD = $(tests_memplus_DEPENDENCIES) $(LIBSASL)
+tests_hash_plus_SOURCES = tests/hash_plus.cc
+tests_hash_plus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX)
+tests_hash_plus_DEPENDENCIES = $(tests_testhashkit_DEPENDENCIES)
+tests_hash_plus_LDADD = $(tests_testhashkit_DEPENDENCIES) $(LIBSASL)
+check_PROGRAMS+= tests/hash_plus
test: check
TESTPLUS_COMMAND= tests/testplus $(COLLECTION) $(SUITE)
-MEMPLUS_COMMAND= tests/memplus $(COLLECTION) $(SUITE)
-
HASHPLUS_COMMAND= tests/hashplus $(COLLECTION) $(SUITE)
ATOM_COMMAND= tests/atomsmasher $(COLLECTION) $(SUITE)
test-hashplus: tests/hashplus
$(HASHPLUS_COMMAND)
-test-memplus: tests/memplus
- $(MEMPLUS_COMMAND)
-
pahole-mem: tests/testapp
$(PAHOLE_COMMAND) $(MEM_COMMAND)
gdb-hashplus: tests/hashplus
$(DEBUG_COMMAND) $(HASHPLUS_COMMAND)
-gdb-memplus: tests/memplus
- $(DEBUG_COMMAND) $(MEMPLUS_COMMAND)
-
gdb-memslap: clients/memslap
$(DEBUG_COMMAND) $(MEMSLAP_COMMAND)
valgrind-hashplus: tests/hashplus
$(VALGRIND_COMMAND) $(HASHPLUS_COMMAND)
-valgrind-memplus: tests/memplus
- $(VALGRIND_COMMAND) $(MEMPLUS_COMMAND)
-
valgrind-memslap: clients/memslap
$(VALGRIND_COMMAND) $(MEMSLAP_COMMAND)
+++ /dev/null
-/*
- C++ to libmemcit
-*/
-#include <libtest/test.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <libmemcached/memcached.h>
-
-static test_return_t exists_test(void *obj)
-{
- Memcached memc;
- (void)obj;
- (void)memc;
-
- return TEST_SUCCESS;
-}
-
-static test_return_t new_test(void *obj)
-{
- Memcached *memc= new Memcached;
- (void)obj;
-
- (void)memc;
-
- delete memc;
-
- return TEST_SUCCESS;
-}
-
-static test_return_t copy_test(void *obj)
-{
- Memcached *memc= new Memcached;
- Memcached *copy(memc);
- (void)obj;
-
- (void)copy;
-
- delete memc;
-
- return TEST_SUCCESS;
-}
-
-static test_return_t assign_test(void *obj)
-{
- Memcached memc;
- Memcached copy;
- (void)obj;
-
- copy= memc;
-
- (void)copy;
-
- return TEST_SUCCESS;
-}
-
-test_st basic[] ={
- { "exists", 0, reinterpret_cast<test_callback_fn>(exists_test) },
- { "new", 0, reinterpret_cast<test_callback_fn>(new_test) },
- { "copy", 0, reinterpret_cast<test_callback_fn>(copy_test) },
- { "assign", 0, reinterpret_cast<test_callback_fn>(assign_test) },
- { 0, 0, 0}
-};
-
-collection_st collection[] ={
- {"basic", 0, 0, basic},
- {0, 0, 0, 0}
-};
-
-void get_world(world_st *world)
-{
- world->collections= collection;
-}