belliottsmith commented on code in PR #50:
URL: https://github.com/apache/cassandra-accord/pull/50#discussion_r1241230556


##########
accord-core/src/main/java/accord/utils/ReducingIntervalMap.java:
##########
@@ -93,35 +99,47 @@ public boolean equals(Object o)
         if (this == o) return true;
         if (o == null || getClass() != o.getClass()) return false;
         ReducingIntervalMap that = (ReducingIntervalMap) o;
-        return Arrays.equals(ends, that.ends) && Arrays.equals(values, 
that.values);
+        return Arrays.equals(starts, that.starts) && Arrays.equals(values, 
that.values);
     }
 
     public int hashCode()
     {
         return Arrays.hashCode(values);
     }
 
+    public boolean inclusiveEnds()
+    {
+        return inclusiveEnds;
+    }
+
     public V get(K key)
     {
-        int idx = Arrays.binarySearch(ends, key);
-        if (idx < 0) idx = -1 - idx;
-        else if (!inclusiveEnds) ++idx;
+        int idx = find(key);
+        if (idx < 0 || idx >= values.length)
+            return null;
         return values[idx];
     }
 
-    public V value(int idx)
+    public K startAt(int idx)
+    {
+        if (idx < 0 || idx > size() - 1)
+            throw new IndexOutOfBoundsException();
+        return starts[idx];
+    }
+
+    public V valueAt(int idx)
     {
         if (idx < 0 || idx > size())
             throw new IndexOutOfBoundsException();
 
         return values[idx];
     }
 
-    public int indexOf(K key)
+    private int find(K key)
     {
-        int idx = Arrays.binarySearch(ends, key);
-        if (idx < 0) idx = -1 - idx;
-        else if (!inclusiveEnds) --idx;
+        int idx = Arrays.binarySearch(starts, key);
+        if (idx < 0) idx = -2 - idx;
+        else if (inclusiveEnds) --idx;

Review Comment:
   This is already covered by `ReducingRangeMapTest`, which I have now updated 
to cover both inclusive and exclusive ends.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to