-
Enhancement
-
Resolution: Fixed
-
P3
-
None
-
b92
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8143520 | emb-9 | Paul Sandoz | P3 | Resolved | Fixed | team |
Such comparators can be declared as methods on Arrays. For example, the signatures for byte array comparator methods could be:
public static int compare(byte[] left, byte[] right);
public static int compare(byte[] left, int lFromIndex, int lToIndex,
byte[] right, int rFromIndex, int rToIndex);
public static int compareUnsigned(byte[] left, byte[] right);
public static int compareUnsigned(byte[] left, int lFromIndex, int lToIndex,
byte[] right, int rFromIndex, int rToIndex);
A Comparator<byte[]> may be obtained as follows:
Comparator<byte[]> c = Arrays::compare;
Comparator<byte[]> cu = Arrays::compareUnsigned;
For such a proposal a maximum of 28 comparator methods will be required: two methods each for eight primitives, two more each for unsigned variants for byte, short, int and long, and four for object references (with a natural Comparator or an explicit Comparator).
Frameworks such as Cassandra and libraries such as Guava provide a Comparator for unsigned byte arrays that internally uses sun.misc.Unsafe to view byte[] as long[] to more efficiently compare 8 bytes at a time (assuming alignment). The unsigned byte array comparator implementation should have similar performance characteristics as Cassandra's and Guava's comparator (most likely using the same technique), thereby reducing the dependency on the sun.misc.Unsafe class.
Customized array equality and comparison can be built upon more general array mismatch functionality, such as:
public static int mismatch(byte[] a, byte[] b);
public static int mismatch(byte[] a, int aFromIndex, int aToIndex,
byte[] b, int bFromIndex, int bToIndex);
A maximum of two methods each for eight primitives, and four for object references () would be required.
- backported by
-
JDK-8143520 Lexicographic comparators and mismatchers for arrays
- Resolved
- blocks
-
JDK-8136924 Vectorized support for array equals/compare/mismatch using Unsafe
- Resolved
-
JDK-8044082 Efficient array comparison intrinsics
- Draft
- duplicates
-
JDK-8048188 (array) Arrays.equals(Object[], Object[]) should be smarter about calling Object.equals
- Closed
- relates to
-
JDK-8026049 (bf) Intrinsify ByteBuffer.put{Int,Double,Float,...} methods
- Resolved
-
JDK-8141409 Arrays.equals accepting a Comparator
- Closed
-
JDK-8143355 Update for addition of vectorizedMismatch intrinsic for x86
- Resolved
-
JDK-8205194 Improve the Array Comparison when there is mismatch at first element.
- Resolved