Java Code Examples for org.apache.hadoop.io.WritableComparator#readLong()

The following examples show how to use org.apache.hadoop.io.WritableComparator#readLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatrixIndexes.java    From systemds with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)
{
	//compare row
	long v1 = WritableComparator.readLong(b1, s1);
    long v2 = WritableComparator.readLong(b2, s2);
    if(v1!=v2)
    	return v1<v2 ? -1 : 1;    
    //compare column (if needed)
	v1 = WritableComparator.readLong(b1, s1+Long.SIZE/8);
	v2 = WritableComparator.readLong(b2, s2+Long.SIZE/8);
	return (v1<v2 ? -1 : (v1==v2 ? 0 : 1));
}
 
Example 2
Source File: MatrixIndexes.java    From systemds with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)
{
	//compare row
	long v1 = WritableComparator.readLong(b1, s1);
    long v2 = WritableComparator.readLong(b2, s2);
    if(v1!=v2)
    	return v1<v2 ? -1 : 1;    
    //compare column (if needed)
	v1 = WritableComparator.readLong(b1, s1+Long.SIZE/8);
	v2 = WritableComparator.readLong(b2, s2+Long.SIZE/8);
	return (v1<v2 ? -1 : (v1==v2 ? 0 : 1));
}
 
Example 3
Source File: AegisthusKey.java    From aegisthus with Apache License 2.0 5 votes vote down vote up
/**
 * Zero copy readFields.
 * Note: As defensive copying is not done, caller should not mutate b1 while using instance.
 * */
public void readFields(byte[] bytes, int start, int length) {
    int pos = start; // start at the input position
    int keyLength = WritableComparator.readInt(bytes, pos);
    pos += 4; // move forward by the int that held the key length
    this.key = ByteBuffer.wrap(bytes, pos, keyLength);
    pos += keyLength; // move forward by the key length

    int pathLength = WritableComparator.readInt(bytes, pos);
    pos += 4; // move forward by the int that held the path length
    if (pathLength > 0) {
        this.sourcePath = new String(bytes, pos, pathLength, Charsets.UTF_8);
    } else {
        this.sourcePath = "";
    }
    pos += pathLength; // move forward by the path length

    int nameLength = WritableComparator.readInt(bytes, pos);
    pos += 4; // move forward by an int that held the name length
    if (nameLength > 0) {
        this.name = ByteBuffer.wrap(bytes, pos, nameLength);
    } else {
        this.name = null;
    }
    pos += nameLength; // move forward by the name length

    if (bytes[pos] == 0) {
        // pos += 1; // move forward by a boolean
        this.timestamp = null;
    } else {
        pos += 1; // move forward by a boolean
        this.timestamp = WritableComparator.readLong(bytes, pos);
        // pos += 8; // move forward by a long
    }
}