MCPcopy Create free account
hub / github.com/OpenTSDB/asynchbase / memcmp

Method memcmp

src/Bytes.java:536–547  ·  view source on GitHub ↗

memcmp in Java, hooray. @param a First non-null byte array to compare. @param b Second non-null byte array to compare. @return 0 if the two arrays are identical, otherwise the difference between the first two different bytes, otherwise the different between their lengths.

(final byte[] a, final byte[] b)

Source from the content-addressed store, hash-verified

534 * their lengths.
535 */
536 public static int memcmp(final byte[] a, final byte[] b) {
537 final int length = Math.min(a.length, b.length);
538 if (a == b) { // Do this after accessing a.length and b.length
539 return 0; // in order to NPE if either a or b is null.
540 }
541 for (int i = 0; i < length; i++) {
542 if (a[i] != b[i]) {
543 return (a[i] & 0xFF) - (b[i] & 0xFF); // "promote" to unsigned.
544 }
545 }
546 return a.length - b.length;
547 }
548
549 /**
550 * {@code memcmp(3)} with a given offset and length.

Callers 12

deDupMethod · 0.95
equalsMethod · 0.95
memcmpMaybeNullMethod · 0.95
compareToMethod · 0.95
compareMethod · 0.95
compareMethod · 0.95
getRegionMethod · 0.95
compareToMethod · 0.95
byteArrayEqualsMethod · 0.95
compareMethod · 0.95
scanFinishedMethod · 0.95
compareMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected