Use XXH3 to instead of java hash. Also filter away NaN.
// 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) {
