diff options
author | Henning Baldersheim <balder@verizonmedia.com> | 2020-03-27 18:52:22 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@verizonmedia.com> | 2020-03-27 19:09:14 +0000 |
commit | 7fce3a5001d93bdfe6b8d6db6e76621552795c51 (patch) | |
tree | 7a67ec738e1d2b9654666839b37f99f828457c9d | |
parent | 14f2bda51b20abb1112d627621db46e282a4b34c (diff) |
Use xxhash for most out hashing. It is significantly better quality hash.
From 0.7.3 is is also significantly faster.
-rw-r--r-- | documentapi/test/crosslanguagefiles/6.221-cpp-CreateVisitorMessage.dat | bin | 193 -> 193 bytes | |||
-rw-r--r-- | searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp | 8 | ||||
-rw-r--r-- | vespalib/src/tests/stllike/hash_test.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/tests/stllike/lookup_benchmark.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/hash_fun.cpp | 21 |
5 files changed, 13 insertions, 20 deletions
diff --git a/documentapi/test/crosslanguagefiles/6.221-cpp-CreateVisitorMessage.dat b/documentapi/test/crosslanguagefiles/6.221-cpp-CreateVisitorMessage.dat Binary files differindex a7bb5b0e896..27e64170701 100644 --- a/documentapi/test/crosslanguagefiles/6.221-cpp-CreateVisitorMessage.dat +++ b/documentapi/test/crosslanguagefiles/6.221-cpp-CreateVisitorMessage.dat diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index 11054566985..898f014cea3 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -447,8 +447,8 @@ void assertAttributes2(const AttributeGuardList &attributes) { EXPECT_EQUAL(2u, attributes.size()); - EXPECT_EQUAL("attr2", attributes[0]->getName()); - EXPECT_EQUAL("attr1", attributes[1]->getName()); + EXPECT_EQUAL("attr1", attributes[0]->getName()); + EXPECT_EQUAL("attr2", attributes[1]->getName()); } void @@ -833,8 +833,8 @@ requireThatAttributesArePopulatedDuringReprocessing(FixtureType &f) std::vector<AttributeGuard> attrs; f.getAttributeManager()->getAttributeList(attrs); EXPECT_EQUAL(2u, attrs.size()); - TEST_DO(assertAttribute1(attrs[1], CFG_SERIAL, 40)); - TEST_DO(assertAttribute2(attrs[0], 40, 40)); + TEST_DO(assertAttribute1(attrs[0], CFG_SERIAL, 40)); + TEST_DO(assertAttribute2(attrs[1], 40, 40)); } } diff --git a/vespalib/src/tests/stllike/hash_test.cpp b/vespalib/src/tests/stllike/hash_test.cpp index b39b6859623..d23c2c6b68c 100644 --- a/vespalib/src/tests/stllike/hash_test.cpp +++ b/vespalib/src/tests/stllike/hash_test.cpp @@ -32,7 +32,7 @@ namespace { TEST("test that hashValue gives expected response") { const char * s("abcdefghi"); - EXPECT_EQUAL(7045194595191919248ul, vespalib::hashValue(s)); + EXPECT_EQUAL(2878261200250560019ul, vespalib::hashValue(s)); EXPECT_EQUAL(vespalib::hashValue(s), vespalib::hashValue(s, strlen(s))); EXPECT_NOT_EQUAL(vespalib::hashValue(s), vespalib::hashValue(s, strlen(s)-1)); } diff --git a/vespalib/src/tests/stllike/lookup_benchmark.cpp b/vespalib/src/tests/stllike/lookup_benchmark.cpp index acde9ea8f9a..dd9f0a7c3e4 100644 --- a/vespalib/src/tests/stllike/lookup_benchmark.cpp +++ b/vespalib/src/tests/stllike/lookup_benchmark.cpp @@ -5,7 +5,7 @@ #include <set> #include <unordered_set> #include <vector> -//#define XXH_INLINE_ALL +#define XXH_INLINE_ALL #include <xxhash.h> #include <vespa/vespalib/stllike/hash_set.hpp> #include <vespa/vespalib/stllike/hash_map.hpp> diff --git a/vespalib/src/vespa/vespalib/stllike/hash_fun.cpp b/vespalib/src/vespa/vespalib/stllike/hash_fun.cpp index d8c6c87ecda..0cb07e68a74 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_fun.cpp +++ b/vespalib/src/vespa/vespalib/stllike/hash_fun.cpp @@ -2,24 +2,22 @@ #include "hash_fun.h" +// Enable inliining when we have xxhash 0.7.3 on all platforms +// #define XXH_INLINE_ALL +#include <xxhash.h> + namespace vespalib { size_t hashValue(const char *str) { - size_t res = 0; - unsigned const char *pt = (unsigned const char *) str; - while (*pt != 0) { - res = (res << 7) + (res >> 25) + *pt++; - } - return res; + return hashValue(str, strlen(str)); } /** * @brief Calculate hash value. * - * This is the hash function used by the HashMap class. - * The hash function is inherited from Fastserver4 / FastLib / pandora. + * The hash function XXH64 from xxhash library. * @param buf input buffer * @param sz input buffer size * @return hash value of input @@ -27,12 +25,7 @@ hashValue(const char *str) size_t hashValue(const void * buf, size_t sz) { - size_t res = 0; - unsigned const char *pt = (unsigned const char *) buf; - for (size_t i(0); i < sz; i++) { - res = (res << 7) + (res >> 25) + pt[i]; - } - return res; + return XXH64(buf, sz, 0); } } |