Example usage for com.google.common.primitives Longs BYTES

List of usage examples for com.google.common.primitives Longs BYTES

Introduction

In this page you can find the example usage for com.google.common.primitives Longs BYTES.

Prototype

int BYTES

To view the source code for com.google.common.primitives Longs BYTES.

Click Source Link

Document

The number of bytes required to represent a primitive long value.

Usage

From source file:org.apache.ignite.hadoop.io.TextPartiallyRawComparator.java

/**
 * Internal comparison routine.//  ww  w  .j a  va2s .  c o m
 *
 * @param buf1 Bytes 1.
 * @param len1 Length 1.
 * @param ptr2 Pointer 2.
 * @param len2 Length 2.
 * @return Result.
 */
@SuppressWarnings("SuspiciousNameCombination")
private static int compareBytes(byte[] buf1, int len1, long ptr2, int len2) {
    int minLength = Math.min(len1, len2);

    int minWords = minLength / Longs.BYTES;

    for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
        long lw = GridUnsafe.getLong(buf1, GridUnsafe.BYTE_ARR_OFF + i);
        long rw = GridUnsafe.getLong(ptr2 + i);

        long diff = lw ^ rw;

        if (diff != 0) {
            if (GridUnsafe.BIG_ENDIAN)
                return (lw + Long.MIN_VALUE) < (rw + Long.MIN_VALUE) ? -1 : 1;

            // Use binary search
            int n = 0;
            int y;
            int x = (int) diff;

            if (x == 0) {
                x = (int) (diff >>> 32);

                n = 32;
            }

            y = x << 16;

            if (y == 0)
                n += 16;
            else
                x = y;

            y = x << 8;

            if (y == 0)
                n += 8;

            return (int) (((lw >>> n) & 0xFFL) - ((rw >>> n) & 0xFFL));
        }
    }

    // The epilogue to cover the last (minLength % 8) elements.
    for (int i = minWords * Longs.BYTES; i < minLength; i++) {
        int res = UnsignedBytes.compare(buf1[i], GridUnsafe.getByte(ptr2 + i));

        if (res != 0)
            return res;
    }

    return len1 - len2;
}

From source file:tachyon.network.protocol.RPCMessageEncoder.java

@Override
protected void encode(ChannelHandlerContext ctx, RPCMessage in, List<Object> out) throws Exception {
    RPCRequest.Type type = in.getType();

    long bodyBytes = 0;
    DataBuffer payload = null;/*from  w  ww.ja  v  a  2  s. co m*/

    if (in.hasPayload()) {
        payload = in.getPayloadDataBuffer();
        bodyBytes = payload.getLength();
    }

    int lengthBytes = Longs.BYTES;
    int typeBytes = type.getEncodedLength();
    int messageBytes = in.getEncodedLength();

    int headerBytes = lengthBytes + typeBytes + messageBytes;
    long frameBytes = headerBytes + bodyBytes;

    // Write the header info into a buffer.
    // The format is: [frame length][message type][message][(optional) data]
    ByteBuf buffer = ctx.alloc().buffer();
    buffer.writeLong(frameBytes);
    type.encode(buffer);
    in.encode(buffer);

    // Output the header buffer.
    out.add(buffer);

    if (payload != null && bodyBytes > 0) {
        Object output = payload.getNettyOutput();
        Preconditions.checkArgument(output instanceof ByteBuf || output instanceof FileRegion,
                "The payload must be a ByteBuf or a FileRegion.");
        out.add(output);
    }

}

From source file:com.metamx.druid.index.v1.CompressedLongBufferObjectStrategy.java

private CompressedLongBufferObjectStrategy(final ByteOrder order) {
    super(order, new BufferConverter<LongBuffer>() {
        @Override/*from   www  .j  ava  2  s .co m*/
        public LongBuffer convert(ByteBuffer buf) {
            return buf.asLongBuffer();
        }

        @Override
        public int compare(LongBuffer lhs, LongBuffer rhs) {
            return Ordering.natural().nullsFirst().compare(lhs, rhs);
        }

        @Override
        public int sizeOf(int count) {
            return count * Longs.BYTES;
        }

        @Override
        public LongBuffer combine(ByteBuffer into, LongBuffer from) {
            return into.asLongBuffer().put(from);
        }
    });
}

From source file:io.druid.segment.data.CompressedLongBufferObjectStrategy.java

private CompressedLongBufferObjectStrategy(final ByteOrder order, final CompressionStrategy compression,
        final int sizePer) {
    super(order, new BufferConverter<LongBuffer>() {
        @Override//  w ww  .  j a va  2 s .  c o  m
        public LongBuffer convert(ByteBuffer buf) {
            return buf.asLongBuffer();
        }

        @Override
        public int compare(LongBuffer lhs, LongBuffer rhs) {
            return Ordering.natural().nullsFirst().compare(lhs, rhs);
        }

        @Override
        public int sizeOf(int count) {
            return count * Longs.BYTES;
        }

        @Override
        public LongBuffer combine(ByteBuffer into, LongBuffer from) {
            return into.asLongBuffer().put(from);
        }
    }, compression, sizePer);
}

From source file:edu.mit.streamjit.util.affinity.LinuxAffinityStrategy.java

@Override
public long getThreadAffinity() {
    Pointer<Long> pmask = null;
    try {/*from  w w w.  j a va  2 s  .  c o  m*/
        pmask = Pointer.allocateLong();
        int ret = sched_getaffinity(0, new SizeT(Longs.BYTES), pmask);
        if (ret != 0)
            throw new RuntimeException();
        return pmask.get();
    } finally {
        if (pmask != null)
            pmask.release();
    }
}

From source file:io.druid.query.aggregation.last.LongLastBufferAggregator.java

@Override
public void aggregate(ByteBuffer buf, int position) {
    long time = timeSelector.get();
    long lastTime = buf.getLong(position);
    if (time >= lastTime) {
        buf.putLong(position, time);/*from w  w w  .  j  a  va2  s. c o  m*/
        buf.putLong(position + Longs.BYTES, valueSelector.get());
    }
}

From source file:io.druid.query.aggregation.last.DoubleLastBufferAggregator.java

@Override
public void aggregate(ByteBuffer buf, int position) {
    long time = timeSelector.get();
    long lastTime = buf.getLong(position);
    if (time >= lastTime) {
        buf.putLong(position, time);/*from w ww. j  a  va2s .co m*/
        buf.putDouble(position + Longs.BYTES, valueSelector.get());
    }
}

From source file:io.druid.query.aggregation.first.DoubleFirstBufferAggregator.java

@Override
public void aggregate(ByteBuffer buf, int position) {
    long time = timeSelector.get();
    long firstTime = buf.getLong(position);
    if (time < firstTime) {
        buf.putLong(position, time);/*  w  ww  . j  ava2 s  .  c  om*/
        buf.putDouble(position + Longs.BYTES, valueSelector.get());
    }
}

From source file:io.druid.query.aggregation.first.LongFirstBufferAggregator.java

@Override
public void aggregate(ByteBuffer buf, int position) {
    long time = timeSelector.getLong();
    long firstTime = buf.getLong(position);
    if (time < firstTime) {
        buf.putLong(position, time);/*from  w w  w . j  ava 2  s .  c  o  m*/
        buf.putLong(position + Longs.BYTES, valueSelector.getLong());
    }
}

From source file:tachyon.network.protocol.RPCBlockReadRequest.java

@Override
public int getEncodedLength() {
    // 3 longs (mBLockId, mOffset, mLength)
    return Longs.BYTES * 3;
}