summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2023-11-08 20:02:24 +0000
committerArne Juul <arnej@yahooinc.com>2023-11-08 20:02:24 +0000
commit3956563e17ea78418657f264d8efae93494c7172 (patch)
tree1e5e711c57f47339b3c14f3a0c3e69366b422639 /vespajlib
parent5c2610e9fa5ae8c293ebe872263d5fd76f525306 (diff)
try to improve hashCode/equals
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java15
1 files changed, 13 insertions, 2 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
index 8298285da19..5b277e4716f 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java
@@ -5,10 +5,12 @@ package com.yahoo.tensor;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
/**
@@ -28,13 +30,22 @@ public class MixedTensor implements Tensor {
private final TensorType type;
private final int blockSize; // aka dense subspace size
- static class DenseBlock {
+ static final class DenseBlock {
final TensorAddress sparseAddr;
final double[] cells;
DenseBlock(TensorAddress sparseAddr, double[] cells) {
this.sparseAddr = sparseAddr;
this.cells = cells;
}
+ @Override public int hashCode() {
+ return Objects.hash(sparseAddr, cells);
+ }
+ @Override public boolean equals(Object other) {
+ if (other instanceof DenseBlock o) {
+ return sparseAddr.equals(o.sparseAddr) && Arrays.equals(cells, o.cells);
+ }
+ return false;
+ }
}
/** The cells in the tensor */
@@ -189,7 +200,7 @@ public class MixedTensor implements Tensor {
}
@Override
- public int hashCode() { return cellBlocks.hashCode(); }
+ public int hashCode() { return Objects.hash(type, cellBlocks); }
@Override
public String toString() {