aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-11-20 19:04:21 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-11-20 19:04:21 +0000
commita7029c97b111f4a518671cbf56188b9bf986945f (patch)
tree0863919cafbbb113133ed0fd8f10a28d14544767 /vespalib
parent37c0e98af2ab7fbeb307019a20e572def4f1ddb6 (diff)
Use XXH3 to instead of java hash. Also filter away NaN.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/string_hash.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/vespalib/src/vespa/vespalib/util/string_hash.cpp b/vespalib/src/vespa/vespalib/util/string_hash.cpp
index 0e8b93dca04..a5212401256 100644
--- a/vespalib/src/vespa/vespalib/util/string_hash.cpp
+++ b/vespalib/src/vespa/vespalib/util/string_hash.cpp
@@ -1,15 +1,19 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "string_hash.h"
+#include <vespa/vespalib/stllike/hash_fun.h>
namespace vespalib {
double hash2d(const char *str, size_t len) {
- uint32_t hash = 0;
- for (size_t i = 0; i < len; ++i) {
- hash = (hash << 5) - hash + str[i];
+ size_t h = hashValue(str, len);
+ if ((h & 0x7ff0000000000000ul) == 0x7ff0000000000000ul) {
+ // Avoid nan
+ h = h & 0xffeffffffffffffful;
}
- return hash;
+ double d = 0;
+ memcpy(&d, &h, sizeof(d));
+ return d;
}
double hash2d(vespalib::stringref str) {