diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-11-21 15:57:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-21 15:57:54 +0100 |
commit | 88a4c159d2fa483e6b1cbcfc7bc56667e3427828 (patch) | |
tree | aba5985c4e43048c896691f0b0ed5038412d91b5 /searchlib | |
parent | 317e07ad20dd9076502606af423adf8c068dd812 (diff) | |
parent | 230816931c1288d004268277942f164088a364b7 (diff) |
Merge pull request #24935 from vespa-engine/bratseth/xxhash
Hash to 64 bits using xxhash
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/StringValue.java | 16 |
1 files changed, 14 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..c668292c0ab 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,8 @@ import com.yahoo.javacc.UnicodeUtilities; import com.yahoo.searchlib.rankingexpression.rule.Function; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; +import net.openhft.hashing.LongHashFunction; +import java.nio.charset.StandardCharsets; /** * A string value. @@ -31,10 +33,20 @@ 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(); + // Hash using the xxh3 algorithm which is also used on content nodes + byte[] data = value.getBytes(StandardCharsets.UTF_8); + long h = LongHashFunction.xx3().hashBytes(data); + if ((h & 0x7ff0000000000000L) == 0x7ff0000000000000L) { + // Avoid nan + h = h & 0xffefffffffffffffL; + } + return Double.longBitsToDouble(h); } @Override |