aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/impl/TensorAddressAny1.java
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2024-01-24 01:33:20 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2024-01-25 20:17:49 +0100
commita1e14c645d88fecfab1abb0072e0abc26677e752 (patch)
tree9d22ff810f3694912005ddc455ca3425699b2fe7 /vespajlib/src/main/java/com/yahoo/tensor/impl/TensorAddressAny1.java
parentd9fb5104948ad6b8758e5a902af3fad0f9e506ce (diff)
Make tensor addresses integer based instead of as strings.
Positive numbers are direct indexes, while strings that does not represent numbers are enumerated and represented with negative integers.
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/impl/TensorAddressAny1.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/impl/TensorAddressAny1.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/impl/TensorAddressAny1.java b/vespajlib/src/main/java/com/yahoo/tensor/impl/TensorAddressAny1.java
new file mode 100644
index 00000000000..a2b0d318a50
--- /dev/null
+++ b/vespajlib/src/main/java/com/yahoo/tensor/impl/TensorAddressAny1.java
@@ -0,0 +1,37 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+package com.yahoo.tensor.impl;
+
+import com.yahoo.tensor.TensorAddress;
+
+/**
+ * Single dimension
+ * @author baldersheim
+ */
+final class TensorAddressAny1 extends TensorAddressAny {
+ private final int label;
+ TensorAddressAny1(int label) { this.label = label; }
+
+ @Override public int size() { return 1; }
+
+ @Override
+ public long numericLabel(int i) {
+ if (i == 0) {
+ return label;
+ }
+ throw new IndexOutOfBoundsException("Index is not zero: " + i);
+ }
+
+ @Override
+ public TensorAddress withLabel(int labelIndex, long label) {
+ if (labelIndex == 0) return new TensorAddressAny1(Convert.safe2Int(label));
+ throw new IllegalArgumentException("No label " + labelIndex);
+ }
+
+ @Override public int hashCode() { return Math.abs(label); }
+
+ @Override
+ public boolean equals(Object o) {
+ return (o instanceof TensorAddressAny1 any) && (label == any.label);
+ }
+}