belliottsmith commented on code in PR #7:
URL: https://github.com/apache/cassandra-accord/pull/7#discussion_r1013042266
##########
accord-core/src/main/java/accord/primitives/AbstractKeys.java:
##########
@@ -0,0 +1,346 @@
+package accord.primitives;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.function.BiFunction;
+import java.util.function.IntFunction;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import accord.api.RoutingKey;
+import accord.utils.IndexedFold;
+import accord.utils.IndexedFoldIntersectToLong;
+import accord.utils.IndexedFoldToLong;
+import accord.utils.IndexedPredicate;
+import accord.utils.IndexedRangeFoldToLong;
+import accord.utils.SortedArrays;
+import net.nicoulaj.compilecommand.annotations.Inline;
+
+@SuppressWarnings("rawtypes")
+// TODO: check that foldl call-sites are inlined and optimised by HotSpot
+public abstract class AbstractKeys<K extends RoutingKey, KS extends
AbstractKeys<K, KS>> implements Iterable<K>
+{
+ final K[] keys;
+
+ protected AbstractKeys(K[] keys)
+ {
+ this.keys = keys;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ AbstractKeys that = (AbstractKeys) o;
+ return Arrays.equals(keys, that.keys);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Arrays.hashCode(keys);
+ }
+
+ public int indexOf(K key)
+ {
+ return Arrays.binarySearch(keys, key);
+ }
+
+ public boolean contains(K key)
+ {
+ return indexOf(key) >= 0;
+ }
+
+ public K get(int indexOf)
+ {
+ return keys[indexOf];
+ }
+
+ /**
+ * return true if this keys collection contains all keys found in the
given keys
+ */
+ public boolean containsAll(AbstractKeys<K, ?> that)
+ {
+ if (that.isEmpty())
+ return true;
+
+ return foldlIntersect(that, (li, ri, k, p, v) -> v + 1, 0, 0, 0) ==
that.size();
+ }
+
+
+ public boolean isEmpty()
+ {
+ return keys.length == 0;
+ }
+
+ public int size()
+ {
+ return keys.length;
+ }
+
+ public int findNext(K key, int startIndex)
+ {
+ return SortedArrays.exponentialSearch(keys, startIndex, keys.length,
key);
+ }
+
+ // returns thisIdx in top 32 bits, thatIdx in bottom
+ public long findNextIntersection(int thisIdx, AbstractKeys<K, ?> that, int
thatIdx)
Review Comment:
Let's leave cleaning this up to `routables`, if necessary
##########
accord-core/src/main/java/accord/primitives/AbstractKeys.java:
##########
@@ -0,0 +1,346 @@
+package accord.primitives;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.function.BiFunction;
+import java.util.function.IntFunction;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import accord.api.RoutingKey;
+import accord.utils.IndexedFold;
+import accord.utils.IndexedFoldIntersectToLong;
+import accord.utils.IndexedFoldToLong;
+import accord.utils.IndexedPredicate;
+import accord.utils.IndexedRangeFoldToLong;
+import accord.utils.SortedArrays;
+import net.nicoulaj.compilecommand.annotations.Inline;
+
+@SuppressWarnings("rawtypes")
+// TODO: check that foldl call-sites are inlined and optimised by HotSpot
+public abstract class AbstractKeys<K extends RoutingKey, KS extends
AbstractKeys<K, KS>> implements Iterable<K>
+{
+ final K[] keys;
+
+ protected AbstractKeys(K[] keys)
+ {
+ this.keys = keys;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ AbstractKeys that = (AbstractKeys) o;
+ return Arrays.equals(keys, that.keys);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Arrays.hashCode(keys);
+ }
+
+ public int indexOf(K key)
+ {
+ return Arrays.binarySearch(keys, key);
+ }
+
+ public boolean contains(K key)
+ {
+ return indexOf(key) >= 0;
+ }
+
+ public K get(int indexOf)
+ {
+ return keys[indexOf];
+ }
+
+ /**
+ * return true if this keys collection contains all keys found in the
given keys
+ */
+ public boolean containsAll(AbstractKeys<K, ?> that)
Review Comment:
Let's leave cleaning this up to `routables`, if necessary
--
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]