summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-11-20 11:14:24 +0100
committerJon Bratseth <bratseth@gmail.com>2022-11-20 11:14:24 +0100
commitc9377b18f70ba1674b1bc257660905142b045028 (patch)
tree2569d19f39991f23d599ae983ead971cf18ab96a /searchlib
parentc535f7e9b1e641d88a0460dc43a47562481770ce (diff)
Hash to 64 bits using xxhash
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java
index a585c989954..be5b4242042 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java
@@ -5,6 +5,10 @@ import com.yahoo.javacc.UnicodeUtilities;
import com.yahoo.searchlib.rankingexpression.rule.Function;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.TensorType;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.charset.StandardCharsets;
/**
* A string value.
@@ -31,10 +35,15 @@ public class StringValue extends Value {
@Override
public TensorType type() { return TensorType.empty; }
- /** Returns the hashcode of this, to enable strings to be encoded (with reasonable safely) as doubles for optimization */
+ /**
+ * Returns the XXHash hashcode of this, to enable strings to be encoded (with reasonable safely)
+ * as doubles for optimization.
+ */
@Override
public double asDouble() {
- return value.hashCode();
+ XXHash64 hasher = XXHashFactory.fastestInstance().hash64();
+ byte[] data = value.getBytes(StandardCharsets.UTF_8);
+ return Double.longBitsToDouble(hasher.hash(data, 0, data.length, 0));
}
@Override