Package com.marksayson.deletionchecker
Class UnsignedBytes
java.lang.Object
com.marksayson.deletionchecker.UnsignedBytes
Lexicographic comparison of byte sequences with each byte treated as unsigned (0..255).
This is the order the dataset is sorted in and searched by. It matches UTF-8 byte order, which
in turn matches Unicode code-point order. Java's signed byte comparison and
String.compareTo(java.lang.String) (UTF-16 code-unit order) both disagree with it for code points above
U+FFFF, so all format code compares through here rather than by either of those.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intlexicographicalCompare(byte[] a, byte[] b) Compares two byte arrays.static intlexicographicalCompare(byte[] a, int aFrom, int aTo, byte[] b, int bFrom, int bTo) Compares a range of one byte array against a range of another.static intlexicographicalCompare(byte[] a, int aFrom, int aTo, ByteBuffer b, int bFrom, int bTo) Compares a range of a byte array against a range of aByteBuffer, reading the buffer by absolute index without disturbing its position or limit.
-
Method Details
-
lexicographicalCompare
public static int lexicographicalCompare(byte[] a, byte[] b) Compares two byte arrays.- Parameters:
a- the first arrayb- the second array- Returns:
- a negative, zero, or positive value as
ais lexicographically less than, equal to, or greater thanb
-
lexicographicalCompare
public static int lexicographicalCompare(byte[] a, int aFrom, int aTo, byte[] b, int bFrom, int bTo) Compares a range of one byte array against a range of another.- Parameters:
a- the first arrayaFrom- the first index ofato compare, inclusiveaTo- the index after the last index ofato compare, exclusiveb- the second arraybFrom- the first index ofbto compare, inclusivebTo- the index after the last index ofbto compare, exclusive- Returns:
- a negative, zero, or positive value as the
arange is lexicographically less than, equal to, or greater than thebrange
-
lexicographicalCompare
public static int lexicographicalCompare(byte[] a, int aFrom, int aTo, ByteBuffer b, int bFrom, int bTo) Compares a range of a byte array against a range of aByteBuffer, reading the buffer by absolute index without disturbing its position or limit.- Parameters:
a- the arrayaFrom- the first index ofato compare, inclusiveaTo- the index after the last index ofato compare, exclusiveb- the bufferbFrom- the first absolute index ofbto compare, inclusivebTo- the absolute index after the last index ofbto compare, exclusive- Returns:
- a negative, zero, or positive value as the
arange is lexicographically less than, equal to, or greater than thebrange
-