@Override public int compare(Object a, Object b) { return compare((WritableComparable)a, (WritableComparable)b); }
private int binarySearch(WritableComparable key) { int low = 0; int high = count-1; while (low <= high) { int mid = (low + high) >>> 1; WritableComparable midVal = keys[mid]; int cmp = comparator.compare(midVal, key); if (cmp < 0) low = mid + 1; else if (cmp > 0) high = mid - 1; else return mid; // key found } return -(low + 1); // key not found. }
@SuppressWarnings("rawtypes") private int compareKey(final WritableComparator comparators[], final int pos, final WritableComparable key_1, final WritableComparable key_2, final boolean nullsafe) { if (key_1 == null && key_2 == null) { if (nullsafe) { return 0; } else { return -1; } } else if (key_1 == null) { return -1; } else if (key_2 == null) { return 1; } if (comparators[pos] == null) { comparators[pos] = WritableComparator.get(key_1.getClass()); } return comparators[pos].compare(key_1, key_2); }
private int compareKeys (List<Object> k1, List<Object> k2) { int ret = 0; // join keys have difference sizes? ret = k1.size() - k2.size(); if (ret != 0) { return ret; } for (int i = 0; i < k1.size(); i++) { WritableComparable key_1 = (WritableComparable) k1.get(i); WritableComparable key_2 = (WritableComparable) k2.get(i); if (key_1 == null && key_2 == null) { return nullsafes != null && nullsafes[i] ? 0 : -1; // just return k1 is smaller than k2 } else if (key_1 == null) { return -1; } else if (key_2 == null) { return 1; } ret = WritableComparator.get(key_1.getClass()).compare(key_1, key_2); if(ret != 0) { return ret; } } return ret; }
@SuppressWarnings("rawtypes") private int compareKey(final WritableComparator comparators[], final int pos, final WritableComparable key_1, final WritableComparable key_2, final boolean nullsafe) { if (key_1 == null && key_2 == null) { if (nullsafe) { return 0; } else { return -1; } } else if (key_1 == null) { return -1; } else if (key_2 == null) { return 1; } if (comparators[pos] == null) { comparators[pos] = WritableComparator.get(key_1.getClass()); } return comparators[pos].compare(key_1, key_2); }
private int compareKeys (List<Object> k1, List<Object> k2) { int ret = 0; // join keys have difference sizes? ret = k1.size() - k2.size(); if (ret != 0) { return ret; } for (int i = 0; i < k1.size(); i++) { WritableComparable key_1 = (WritableComparable) k1.get(i); WritableComparable key_2 = (WritableComparable) k2.get(i); if (key_1 == null && key_2 == null) { return nullsafes != null && nullsafes[i] ? 0 : -1; // just return k1 is smaller than k2 } else if (key_1 == null) { return -1; } else if (key_2 == null) { return 1; } ret = WritableComparator.get(key_1.getClass()).compare(key_1, key_2); if(ret != 0) { return ret; } } return ret; }
if (lastKey != null && comparator.compare(lastKey, k) > 0) throw new IOException("key out of order: "+k+" after "+lastKey); lastKey = k;
if (currentKey == null || comparator.compare(currentKey, keys[i]) > 0) { currentEntry = i; currentKey = keys[i];
private void checkKey(WritableComparable key) throws IOException { // check that keys are well-ordered if (size != 0 && comparator.compare(lastKey, key) > 0) throw new IOException("key out of order: "+key+" after "+lastKey); // update lastKey with a copy of key by writing and reading outBuf.reset(); key.write(outBuf); // write new key inBuf.reset(outBuf.getData(), outBuf.getLength()); lastKey.readFields(inBuf); // read into lastKey }
/** Optimization hook. Override this to make SequenceFile.Sorter's scream. * * <p>The default implementation reads the data into two {@link * WritableComparable}s (using {@link * Writable#readFields(DataInput)}, then calls {@link * #compare(WritableComparable,WritableComparable)}. */ @Override public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { try { buffer.reset(b1, s1, l1); // parse key1 key1.readFields(buffer); buffer.reset(b2, s2, l2); // parse key2 key2.readFields(buffer); buffer.reset(null, 0, 0); // clean up reference } catch (IOException e) { throw new RuntimeException(e); } return compare(key1, key2); // compare them }
@Override public int compare(int i, int j) { final int ii = indices[i]; final int ij = indices[j]; return comparator.compare(bytes, offsets[ii], ((ii + 1 == indices.length) ? eob : offsets[ii + 1]) - offsets[ii], bytes, offsets[ij], ((ij + 1 == indices.length) ? eob : offsets[ij + 1]) - offsets[ij]); }
public int compare(ComposableRecordReader<K,?> o1, ComposableRecordReader<K,?> o2) { return cmp.compare(o1.key(), o2.key()); } });
/** * Implement Comparable contract (compare key at head of proxied RR * with that of another). */ public int compareTo(ComposableRecordReader<K,?> other) { return cmp.compare(key(), other.key()); }
/** * Implement Comparable contract (compare key of join or head of heap * with that of another). */ public int compareTo(ComposableRecordReader<K,?> other) { return cmp.compare(key(), other.key()); }
/** * Skip key-value pairs with keys less than or equal to the key provided. */ public void skip(K key) throws IOException { if (hasNext()) { while (cmp.compare(khead, key) <= 0 && next()); } }
/** * Implement Comparable contract (compare key of join or head of heap * with that of another). */ public int compareTo(ComposableRecordReader<K,?> other) { return cmp.compare(key(), other.key()); }
public int compare(ComposableRecordReader<K,?> o1, ComposableRecordReader<K,?> o2) { return cmp.compare(o1.key(), o2.key()); } });
/** * Skip key-value pairs with keys less than or equal to the key provided. */ public void skip(K key) throws IOException { if (hasNext()) { while (cmp.compare(khead, key) <= 0 && next()); } }
private int compare(WritableComparator writableComparator, DataOutputBuffer buf1, DataOutputBuffer buf2) { return writableComparator.compare(buf1.getData(), 0, buf1.size(), buf2.getData(), 0, buf2.size()); }