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


##########
accord-core/src/main/java/accord/primitives/KeyRanges.java:
##########
@@ -116,44 +119,64 @@ public KeyRanges select(int[] indexes)
         return ofSortedAndDeoverlapped(selection);
     }
 
-    public boolean intersects(Keys keys)
+    public boolean intersects(AbstractKeys<?, ?> keys)
     {
         return findNextIntersection(0, keys, 0) >= 0;
     }
 
+    public <K extends RoutingKey> boolean intersects(AbstractKeys<K, ?> keys, 
Predicate<? super K> matches)
+    {
+        int ri = 0, ki = 0;
+        while (true)
+        {
+            long rki = findNextIntersection(ri, keys, ki);
+            if (rki < 0)
+                return false;
+
+            ri = (int) (rki >>> 32);
+            ki = (int) (rki);
+
+            if (matches.test(keys.get(ki)))
+                return true;
+
+            ki++;
+        }
+    }
+
     public boolean intersects(KeyRanges that)
     {
         return SortedArrays.findNextIntersection(this.ranges, 0, that.ranges, 
0, KeyRange::compareIntersecting) >= 0;
     }
 
-    public int findFirstKey(Keys keys)
+    public int findFirstKey(AbstractKeys<?, ?> keys)
     {
         return findNextKey(0, keys, 0);
     }
 
-    public int findNextKey(int ri, Keys keys, int ki)
+    public int findNextKey(int ri, AbstractKeys<?, ?> keys, int ki)
     {
-        return (int) (findNextIntersection(ri, keys, ki) >> 32);
+        return (int) findNextIntersection(ri, keys, ki);
     }
 
-    // returns ki in top 32 bits, ri in bottom, or -1 if no match found
-    public long findNextIntersection(int ri, Keys keys, int ki)
+    // returns ri in top 32 bits, ki in bottom, or -1 if no match found
+    // TODO (now): inconsistent bits order vs SortedArrays
+    public long findNextIntersection(int ri, AbstractKeys<?, ?> keys, int ki)
     {
-        return SortedArrays.findNextIntersectionWithMultipleMatches(keys.keys, 
ki, ranges, ri);
+        return 
swapHighLow32b(SortedArrays.findNextIntersectionWithMultipleMatches(keys.keys, 
ki, ranges, ri));

Review Comment:
   I thought the context made it reasonably obvious? There's a keys parameter, 
and a ki (keys index); a ranges parameter and ri (range index). In general, I 
use ri, ki, ai, bi to refer to range index, key index, `as` index (for some 
collection/array `as`), `bs` index (similarly). 
   
   `mi` I often combine with a _simple_ `i` to indicate its limit (i.e. max 
index). This is never mixed with the above scenario. If this is less clear, I'd 
be happy to change it.



-- 
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