Example usage for org.apache.hadoop.io WritableComparator compareBytes

List of usage examples for org.apache.hadoop.io WritableComparator compareBytes

Introduction

In this page you can find the example usage for org.apache.hadoop.io WritableComparator compareBytes.

Prototype

public static int compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) 

Source Link

Document

Lexicographic order of binary data.

Usage

From source file:boa.io.EmitKey.java

License:Apache License

/** {@inheritDoc} */
@Override//  w  w w . j av  a  2  s.  co m
public int compare(final byte[] b1, final int s1, final int l1, final byte[] b2, final int s2, final int l2) {
    return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
}

From source file:cascading.tuple.hadoop.BytesComparator.java

License:Open Source License

@Override
public int compare(byte[] lhs, byte[] rhs) {
    if (lhs == rhs)
        return 0;

    return WritableComparator.compareBytes(lhs, 0, lhs.length, rhs, 0, rhs.length);
}

From source file:cascading.tuple.hadoop.BytesComparator.java

License:Open Source License

@Override
public int compare(BufferedInputStream lhsStream, BufferedInputStream rhsStream) {
    byte[] lhs = lhsStream.getBuffer();
    int lhsPos = lhsStream.getPosition();
    int lhsLen = readLen(lhs, lhsPos);

    lhsStream.skip(lhsLen + 4);//from  ww w . ja  v a2 s.  c  o  m

    byte[] rhs = rhsStream.getBuffer();
    int rhsPos = rhsStream.getPosition();
    int rhsLen = readLen(rhs, rhsPos);

    rhsStream.skip(rhsLen + 4);

    return WritableComparator.compareBytes(lhs, lhsPos + 4, lhsLen, rhs, rhsPos + 4, rhsLen);
}

From source file:co.nubetech.hiho.dedup.HihoTuple.java

License:Apache License

@Override
public int compareTo(HihoTuple hihoTuple) {
    return WritableComparator.compareBytes(this.hash.getDigest(), 0, this.hash.MD5_LEN,
            hihoTuple.hash.getDigest(), 0, hihoTuple.hash.MD5_LEN);
}

From source file:com.asakusafw.runtime.stage.collector.SortableSlot.java

License:Apache License

@Override
public int compareTo(SortableSlot o) {
    if (slotNumber < o.slotNumber) {
        return -1;
    } else if (slotNumber > o.slotNumber) {
        return +1;
    }/*from  w w w  .jav a2 s  . c o  m*/
    return WritableComparator.compareBytes(buffer.getData(), 0, buffer.getReadLimit(), o.buffer.getData(), 0,
            o.buffer.getReadLimit());
}

From source file:com.asakusafw.runtime.stage.directio.StringTemplate.java

License:Apache License

/**
 * Compares two objects in bytes./*from  ww  w .  jav  a 2  s  .  c o m*/
 * @param b1 bytes representation of the first object
 * @param o1 offset of the first object
 * @param b2 bytes representation of the second object
 * @param o2 offset of the second object
 * @return the comparison result
 * @throws IOException if failed to comparison
 */
@Override
public final int compareInBytes(byte[] b1, int o1, byte[] b2, int o2) throws IOException {
    int l1 = getSizeInBytes(b1, o1);
    int l2 = getSizeInBytes(b2, o2);
    return WritableComparator.compareBytes(b1, o1, l1, b2, o2, l2);
}

From source file:com.asakusafw.runtime.util.BasicByteArrayComparator.java

License:Apache License

@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
    return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
}

From source file:com.asakusafw.runtime.value.DoubleOption.java

License:Apache License

/**
 * ???2?????/*from   ww  w  . ja v a 2s .  c  o  m*/
 * @param b1 ???
 * @param s1 ?????
 * @param l1 ???????????????
 * @param b2 ???
 * @param s2 ?????
 * @param l2 ???????????????
 * @return ?
 */
public static int compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
    int len1 = getBytesLength(b1, s1, l1);
    int len2 = getBytesLength(b2, s2, l2);
    return WritableComparator.compareBytes(b1, s1, len1, b2, s2, len2);
}

From source file:com.bah.culvert.data.CKeyValue.java

License:Apache License

@Override
public int compareTo(CKeyValue other) {
    int compare = this.compareKey(other);
    if (compare == 0)
        compare = WritableComparator.compareBytes(this.value, 0, this.value.length, other.value, 0,
                other.value.length);//  w  ww . ja v a2  s .  c o m

    return compare;
}

From source file:com.bah.culvert.data.CKeyValue.java

License:Apache License

/**
 * Compares the key portion of a KeyValue
 * @param other to compare to//from w ww.  j  a v a2  s .c o m
 * @return 0 if they are equal, a byte wise comparison of rowId, family,
 *         qualifier, and then timestamp
 */
public int compareKey(CKeyValue other) {
    int compare = WritableComparator.compareBytes(this.rowId, 0, this.rowId.length, other.rowId, 0,
            other.rowId.length);
    if (compare != 0) {
        return compare;
    }

    compare = WritableComparator.compareBytes(this.family, 0, this.family.length, other.family, 0,
            other.family.length);
    if (compare != 0) {
        return compare;
    }

    compare = WritableComparator.compareBytes(this.qualifier, 0, this.qualifier.length, other.qualifier, 0,
            other.qualifier.length);
    if (compare != 0) {
        return compare;
    }

    // TODO add this back in when we are considering time stamps
    // if(this.timestamp < other.timestamp)
    // return -1;
    // else if(this.timestamp > other.timestamp)
    // return 1;

    return compare;
}