From c88563b65a81ad1743f26ad66376704d84043a33 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sat, 10 Sep 2011 13:55:02 -0700 Subject: [PATCH] Ubuntu 10.10 32bit fixes. --- libhashkit/fnv.cc | 75 ------------------------------------------ libhashkit/fnv_32.cc | 73 ++++++++++++++++++++++++++++++++++++++++ libhashkit/fnv_64.cc | 73 ++++++++++++++++++++++++++++++++++++++++ libhashkit/include.am | 3 +- libtest/comparison.hpp | 8 ++--- tests/mem_functions.cc | 2 +- 6 files changed, 153 insertions(+), 81 deletions(-) delete mode 100644 libhashkit/fnv.cc create mode 100644 libhashkit/fnv_32.cc create mode 100644 libhashkit/fnv_64.cc diff --git a/libhashkit/fnv.cc b/libhashkit/fnv.cc deleted file mode 100644 index 7a22cee0..00000000 --- a/libhashkit/fnv.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* HashKit - * Copyright (C) 2009 Brian Aker - * All rights reserved. - * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. - */ - -#include - -/* FNV hash'es lifted from Dustin Sallings work */ -static uint64_t FNV_64_INIT= uint64_t(0xcbf29ce484222325); -static uint64_t FNV_64_PRIME= uint64_t(0x100000001b3); -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, void *context) -{ - /* Thanks to pierre@demartines.com for the pointer */ - uint64_t hash= FNV_64_INIT; - (void)context; - - for (size_t x= 0; x < key_length; x++) - { - hash *= FNV_64_PRIME; - hash ^= (uint64_t)key[x]; - } - - return (uint32_t)hash; -} - -uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *context) -{ - uint32_t hash= (uint32_t) FNV_64_INIT; - (void)context; - - for (size_t x= 0; x < key_length; x++) - { - uint32_t val= (uint32_t)key[x]; - hash ^= val; - hash *= (uint32_t) FNV_64_PRIME; - } - - return hash; -} - -uint32_t hashkit_fnv1_32(const char *key, size_t key_length, void *context) -{ - uint32_t hash= FNV_32_INIT; - (void)context; - - for (size_t x= 0; x < key_length; x++) - { - uint32_t val= (uint32_t)key[x]; - hash *= FNV_32_PRIME; - hash ^= val; - } - - return hash; -} - -uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context) -{ - uint32_t hash= FNV_32_INIT; - (void)context; - - for (size_t x= 0; x < key_length; x++) - { - uint32_t val= (uint32_t)key[x]; - hash ^= val; - hash *= FNV_32_PRIME; - } - - return hash; -} diff --git a/libhashkit/fnv_32.cc b/libhashkit/fnv_32.cc new file mode 100644 index 00000000..5c885164 --- /dev/null +++ b/libhashkit/fnv_32.cc @@ -0,0 +1,73 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * HashKit library + * + * 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. + * + */ + + +#include + +/* FNV hash'es lifted from Dustin Sallings work */ +static uint32_t FNV_32_INIT= 2166136261UL; +static uint32_t FNV_32_PRIME= 16777619; + +uint32_t hashkit_fnv1_32(const char *key, size_t key_length, void *context) +{ + uint32_t hash= FNV_32_INIT; + (void)context; + + for (size_t x= 0; x < key_length; x++) + { + uint32_t val= (uint32_t)key[x]; + hash *= FNV_32_PRIME; + hash ^= val; + } + + return hash; +} + +uint32_t hashkit_fnv1a_32(const char *key, size_t key_length, void *context) +{ + uint32_t hash= FNV_32_INIT; + (void)context; + + for (size_t x= 0; x < key_length; x++) + { + uint32_t val= (uint32_t)key[x]; + hash ^= val; + hash *= FNV_32_PRIME; + } + + return hash; +} diff --git a/libhashkit/fnv_64.cc b/libhashkit/fnv_64.cc new file mode 100644 index 00000000..842e1d5c --- /dev/null +++ b/libhashkit/fnv_64.cc @@ -0,0 +1,73 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * HashKit library + * + * 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. + * + */ + + +#include + +/* FNV hash'es lifted from Dustin Sallings work */ +static uint64_t FNV_64_INIT= 0xcbf29ce484222325LLU; +static uint64_t FNV_64_PRIME= 0x100000001b3LLU; + +uint32_t hashkit_fnv1_64(const char *key, size_t key_length, void *context) +{ + /* Thanks to pierre@demartines.com for the pointer */ + uint64_t hash= FNV_64_INIT; + (void)context; + + for (size_t x= 0; x < key_length; x++) + { + hash *= FNV_64_PRIME; + hash ^= (uint64_t)key[x]; + } + + return (uint32_t)hash; +} + +uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *context) +{ + uint32_t hash= (uint32_t) FNV_64_INIT; + (void)context; + + for (size_t x= 0; x < key_length; x++) + { + uint32_t val= (uint32_t)key[x]; + hash ^= val; + hash *= (uint32_t) FNV_64_PRIME; + } + + return hash; +} diff --git a/libhashkit/include.am b/libhashkit/include.am index f3d2d0e3..90d623a1 100644 --- a/libhashkit/include.am +++ b/libhashkit/include.am @@ -36,7 +36,8 @@ libhashkit_libhashkit_la_SOURCES= \ libhashkit/behavior.cc \ libhashkit/crc32.cc \ libhashkit/digest.cc \ - libhashkit/fnv.cc \ + libhashkit/fnv_32.cc \ + libhashkit/fnv_64.cc \ libhashkit/function.cc \ libhashkit/hashkit.cc \ libhashkit/jenkins.cc \ diff --git a/libtest/comparison.hpp b/libtest/comparison.hpp index a04038b6..eb240d47 100644 --- a/libtest/comparison.hpp +++ b/libtest/comparison.hpp @@ -45,8 +45,8 @@ bool _compare_truth_hint(const char *file, int line, const char *func, T_compara return true; } -template -bool _compare(const char *file, int line, const char *func, const T_comparable __expected, const T_comparable __actual) +template +bool _compare(const char *file, int line, const char *func, const T1_comparable __expected, const T2_comparable __actual) { if (__expected != __actual) { @@ -113,8 +113,8 @@ bool _truth(const char *file, int line, const char *func, T_comparable __truth) return true; } -template -bool _compare_hint(const char *file, int line, const char *func, T_comparable __expected, T_comparable __actual, T_hint __hint) +template +bool _compare_hint(const char *file, int line, const char *func, T1_comparable __expected, T2_comparable __actual, T_hint __hint) { if (__expected != __actual) { diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index a205b565..b4eed62b 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -5579,7 +5579,7 @@ static test_return_t regression_bug_655423(memcached_st *memc) test_compare(MEMCACHED_SUCCESS, rc); test_true(value); - test_compare(100UL, value_length); + test_compare(100LLU, value_length); free(value); } -- 2.30.2