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:com.metamx.druid.index.v1.CompressedLongsSupplierSerializer.java

public static CompressedLongsSupplierSerializer create(IOPeon ioPeon, final String filenameBase,
        final ByteOrder order) throws IOException {
    final CompressedLongsSupplierSerializer retVal = new CompressedLongsSupplierSerializer(0xFFFF / Longs.BYTES,
            new GenericIndexedWriter<ResourceHolder<LongBuffer>>(ioPeon, filenameBase,
                    CompressedLongBufferObjectStrategy.getBufferForOrder(order)));
    return retVal;
}

From source file:org.apache.tajo.tuple.offheap.UnSafeTupleBytesComparator.java

public static int compare(long ptr1, long ptr2) {
    int lstrLen = UNSAFE.getInt(ptr1);
    int rstrLen = UNSAFE.getInt(ptr2);

    ptr1 += SizeOf.SIZE_OF_INT;/*w ww  . ja va2 s.  c  om*/
    ptr2 += SizeOf.SIZE_OF_INT;

    int minLength = Math.min(lstrLen, rstrLen);
    int minWords = minLength / Longs.BYTES;

    /*
     * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
     * time is no slower than comparing 4 bytes at a time even on 32-bit.
     * On the other hand, it is substantially faster on 64-bit.
     */
    for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
        long lw = UNSAFE.getLong(ptr1);
        long rw = UNSAFE.getLong(ptr2);
        long diff = lw ^ rw;

        if (diff != 0) {
            if (!littleEndian) {
                return UnsignedLongs.compare(lw, rw);
            }

            // 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));
        }

        ptr1 += SizeOf.SIZE_OF_LONG;
        ptr2 += SizeOf.SIZE_OF_LONG;
    }

    // The epilogue to cover the last (minLength % 8) elements.
    for (int i = minWords * Longs.BYTES; i < minLength; i++) {
        int result = UNSAFE.getByte(ptr1++) - UNSAFE.getByte(ptr2++);
        if (result != 0) {
            return result;
        }
    }
    return lstrLen - rstrLen;
}

From source file:com.yandex.yoctodb.util.UnsignedByteArrays.java

public static long toLong(@NotNull final UnsignedByteArray bytes) {
    if (bytes.length() != Longs.BYTES)
        throw new IllegalArgumentException("Wrong length");

    return Longs.fromByteArray(bytes.data) ^ Long.MIN_VALUE;
}

From source file:org.apache.tajo.tuple.memory.UnSafeTupleBytesComparator.java

public static int compare(long ptr1, long ptr2) {
    int lstrLen = UNSAFE.getInt(ptr1);
    int rstrLen = UNSAFE.getInt(ptr2);

    ptr1 += SizeOf.SIZE_OF_INT;//from   w  ww  .  j  a  va 2  s .  c o  m
    ptr2 += SizeOf.SIZE_OF_INT;

    int minLength = Math.min(lstrLen, rstrLen);
    int minWords = minLength / Longs.BYTES;

    /*
     * Compare 8 bytes at a time. Benchmarking shows comparing 8 bytes at a
     * time is no slower than comparing 4 bytes at a time even on 32-bit.
     * On the other hand, it is substantially faster on 64-bit.
    */
    for (int i = 0; i < minWords * Longs.BYTES; i += Longs.BYTES) {
        long lw = UNSAFE.getLong(ptr1);
        long rw = UNSAFE.getLong(ptr2);

        if (lw != rw) {
            if (!littleEndian) {
                return UnsignedLongs.compare(lw, rw);
            }

            /*
             * We want to compare only the first index where left[index] != right[index].
             * This corresponds to the least significant nonzero byte in lw ^ rw, since lw
             * and rw are little-endian.  Long.numberOfTrailingZeros(diff) tells us the least
             * significant nonzero bit, and zeroing out the first three bits of L.nTZ gives us the
             * shift to get that least significant nonzero byte.
            */
            int n = Long.numberOfTrailingZeros(lw ^ rw) & ~0x7;
            return (int) (((lw >>> n) & UNSIGNED_MASK) - ((rw >>> n) & UNSIGNED_MASK));
        }

        ptr1 += SizeOf.SIZE_OF_LONG;
        ptr2 += SizeOf.SIZE_OF_LONG;
    }

    // The epilogue to cover the last (minLength % 8) elements.
    for (int i = minWords * Longs.BYTES; i < minLength; i++) {
        int result = UnsignedBytes.compare(UNSAFE.getByte(ptr1++), UNSAFE.getByte(ptr2++));
        if (result != 0) {
            return result;
        }
    }
    return lstrLen - rstrLen;
}

From source file:co.paralleluniverse.galaxy.server.MainMemoryEntry.java

public MainMemoryEntry(byte[] buffer) {
    this.version = Longs.fromByteArray(buffer);
    this.data = new byte[buffer.length - (Longs.BYTES)];
    System.arraycopy(buffer, Longs.BYTES, data, 0, data.length);
}

From source file:co.paralleluniverse.galaxy.server.MainMemoryEntry.java

public byte[] toByteArray() {
    final byte[] buffer = new byte[Longs.BYTES + (data != null ? data.length : 0)];
    BerkeleyDB.toByteArray(version, buffer);
    if (data != null)
        System.arraycopy(data, 0, buffer, Longs.BYTES, data.length);
    return buffer;
}

From source file:io.druid.query.groupby.epinephelinae.column.LongGroupByColumnSelectorStrategy.java

@Override
public int getGroupingKeySize() {
    return Longs.BYTES;
}

From source file:com.ebay.pulsar.analytics.metricstore.druid.granularity.DurationGranularity.java

@Override
public byte[] cacheKey() {
    return ByteBuffer.allocate(2 * Longs.BYTES).putLong(Long.valueOf(duration))
            .putLong(new DateTime(origin).getMillis()).array();
}

From source file:io.druid.query.aggregation.HistogramBufferAggregator.java

public HistogramBufferAggregator(FloatColumnSelector selector, float[] breaks) {
    this.selector = selector;
    this.breaks = breaks;
    this.minOffset = Longs.BYTES * (breaks.length + 1);
    this.maxOffset = this.minOffset + Floats.BYTES;
}

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

public LongsLongEncodingWriter(ByteOrder order) {
    this.order = order;
    orderBuffer = ByteBuffer.allocate(Longs.BYTES);
    orderBuffer.order(order);
}