@Test public void testCommonPrefix() { ArrayByteSequence exact = new ArrayByteSequence("abc"); assertEquals(-1, RelativeKey.getCommonPrefix(exact, exact)); assertEquals(-1, commonPrefixHelper("", "")); assertEquals(-1, commonPrefixHelper("a", "a")); assertEquals(-1, commonPrefixHelper("aa", "aa")); assertEquals(-1, commonPrefixHelper("aaa", "aaa")); assertEquals(-1, commonPrefixHelper("abab", "abab")); assertEquals(-1, commonPrefixHelper(new String("aaa"), new ArrayByteSequence("aaa").toString())); assertEquals(-1, commonPrefixHelper("abababababab".substring(3, 6), "ccababababcc".substring(3, 6))); assertEquals(0, commonPrefixHelper("", "a")); assertEquals(0, commonPrefixHelper("a", "")); assertEquals(0, commonPrefixHelper("a", "b")); assertEquals(0, commonPrefixHelper("aaaa", "bbbb")); assertEquals(1, commonPrefixHelper("a", "ab")); assertEquals(1, commonPrefixHelper("ab", "ac")); assertEquals(1, commonPrefixHelper("ab", "ac")); assertEquals(2, commonPrefixHelper("aa", "aaaa")); assertEquals(4, commonPrefixHelper("aaaaa", "aaaab")); }
static int getCommonPrefix(ByteSequence prev, ByteSequence cur) { if (prev == cur) return -1; int prevLen = prev.length(); int curLen = cur.length(); int maxChecks = Math.min(prevLen, curLen); int common = 0; while (common < maxChecks) { int a = prev.byteAt(common) & 0xff; int b = cur.byteAt(common) & 0xff; if (a != b) return common; common++; } return prevLen == curLen ? -1 : maxChecks; }
RelativeKey implements Writable { static int getCommonPrefix(ByteSequence prev, ByteSequence cur) { if (prev == cur) return -1; int prevLen = prev.length(); int curLen = cur.length(); int maxChecks = Math.min(prevLen, curLen); int common = 0; while (common < maxChecks) { int a = prev.byteAt(common) & 0xff; int b = cur.byteAt(common) & 0xff; if (a != b) return common; common++; } return prevLen == curLen ? -1 : maxChecks; } }
RelativeKey implements Writable { static int getCommonPrefix(ByteSequence prev, ByteSequence cur) { if (prev == cur) return -1; int prevLen = prev.length(); int curLen = cur.length(); int maxChecks = Math.min(prevLen, curLen); int common = 0; while (common < maxChecks) { int a = prev.byteAt(common) & 0xff; int b = cur.byteAt(common) & 0xff; if (a != b) return common; common++; } return prevLen == curLen ? -1 : maxChecks; } RelativeKey();  RelativeKey(Key prevKey, Key key); }
RelativeKey implements Writable { static int getCommonPrefix(ByteSequence prev, ByteSequence cur) { if (prev == cur) return -1; int prevLen = prev.length(); int curLen = cur.length(); int maxChecks = Math.min(prevLen, curLen); int common = 0; while (common < maxChecks) { int a = prev.byteAt(common) & 0xff; int b = cur.byteAt(common) & 0xff; if (a != b) return common; common++; } return prevLen == curLen ? -1 : maxChecks; } RelativeKey();  RelativeKey(Key prevKey, Key key); void setPrevKey(Key pk); @Override void readFields(DataInput in); static SkippR fastSkip(DataInput in, Key seekKey, MutableByteSequence value, Key prevKey,
      Key currKey, int entriesLeft); Key getKey(); @Override void write(DataOutput out); }
RelativeKey implements Writable { static int getCommonPrefix(ByteSequence prev, ByteSequence cur) { if (prev == cur) return -1; int prevLen = prev.length(); int curLen = cur.length(); int maxChecks = Math.min(prevLen, curLen); int common = 0; while (common < maxChecks) { int a = prev.byteAt(common) & 0xff; int b = cur.byteAt(common) & 0xff; if (a != b) return common; common++; } return prevLen == curLen ? -1 : maxChecks; } RelativeKey();  RelativeKey(Key prevKey, Key key); void setPrevKey(Key pk); @Override void readFields(DataInput in); static SkippR fastSkip(DataInput in, Key seekKey, MutableByteSequence value, Key prevKey,
      Key currKey, int entriesLeft); Key getKey(); @Override void write(DataOutput out);  }