List of usage examples for io.netty.util.internal PlatformDependent getByte
public static byte getByte(long address)
From source file:org.apache.activemq.artemis.utils.AbstractByteBufPool.java
License:Apache License
private static int offHeapHashCode(final long address, final int offset, final int length) { final int intCount = length >>> 1; final int byteCount = length & 1; int hashCode = 1; int arrayIndex = offset; for (int i = 0; i < intCount; i++) { hashCode = 31 * hashCode + PlatformDependent.getShort(address + arrayIndex); arrayIndex += 2;//ww w. jav a 2 s. c o m } for (int i = 0; i < byteCount; i++) { hashCode = 31 * hashCode + PlatformDependent.getByte(address + arrayIndex++); } return hashCode; }
From source file:org.apache.activemq.artemis.utils.UTF8Util.java
License:Apache License
private static String unsafeOffHeapReadUTF(final long addressBytes, final int index, final char[] chars, final int size) { int count = index; final int limit = index + size; int byte1, byte2, byte3; int charCount = 0; while (count < limit) { byte1 = PlatformDependent.getByte(addressBytes + count++); if (byte1 >= 0 && byte1 <= 0x7F) { chars[charCount++] = (char) byte1; } else {/*from w w w. jav a2s.c o m*/ int c = byte1 & 0xff; switch (c >> 4) { case 0xc: case 0xd: byte2 = PlatformDependent.getByte(addressBytes + count++); chars[charCount++] = (char) ((c & 0x1F) << 6 | byte2 & 0x3F); break; case 0xe: byte2 = PlatformDependent.getByte(addressBytes + count++); byte3 = PlatformDependent.getByte(addressBytes + count++); chars[charCount++] = (char) ((c & 0x0F) << 12 | (byte2 & 0x3F) << 6 | (byte3 & 0x3F) << 0); break; default: throw new InternalError("unhandled utf8 byte " + c); } } } return new String(chars, 0, charCount); }
From source file:org.apache.arrow.vector.DecimalVector.java
License:Apache License
/** * Sets the element at given index using the buffer whose size maybe <= 16 bytes. * @param index index to write the decimal to * @param start start of value in the buffer * @param buffer contains the decimal in little endian bytes * @param length length of the value in the buffer */// www . j a va2 s.c o m public void setSafe(int index, int start, ArrowBuf buffer, int length) { handleSafe(index); BitVectorHelper.setValidityBitToOne(validityBuffer, index); // do the bound checks. buffer.checkBytes(start, start + length); valueBuffer.checkBytes(index * TYPE_WIDTH, (index + 1) * TYPE_WIDTH); long inAddress = buffer.memoryAddress() + start; long outAddress = valueBuffer.memoryAddress() + index * TYPE_WIDTH; PlatformDependent.copyMemory(inAddress, outAddress, length); // sign extend if (length < 16) { byte msb = PlatformDependent.getByte(inAddress + length - 1); final byte pad = (byte) (msb < 0 ? 0xFF : 0x00); PlatformDependent.setMemory(outAddress + length, DecimalVector.TYPE_WIDTH - length, pad); } }
From source file:org.apache.arrow.vector.DecimalVector.java
License:Apache License
/** * Sets the element at given index using the buffer whose size maybe <= 16 bytes. * @param index index to write the decimal to * @param start start of value in the buffer * @param buffer contains the decimal in big endian bytes * @param length length of the value in the buffer *///from w w w .j a v a 2 s .c om public void setBigEndianSafe(int index, int start, ArrowBuf buffer, int length) { handleSafe(index); BitVectorHelper.setValidityBitToOne(validityBuffer, index); // do the bound checks. buffer.checkBytes(start, start + length); valueBuffer.checkBytes(index * TYPE_WIDTH, (index + 1) * TYPE_WIDTH); // not using buffer.getByte() to avoid boundary checks for every byte. long inAddress = buffer.memoryAddress() + start; long outAddress = valueBuffer.memoryAddress() + index * TYPE_WIDTH; // swap bytes to convert BE to LE for (int byteIdx = 0; byteIdx < length; ++byteIdx) { byte val = PlatformDependent.getByte((inAddress + length - 1) - byteIdx); PlatformDependent.putByte(outAddress + byteIdx, val); } // sign extend if (length < 16) { byte msb = PlatformDependent.getByte(inAddress); final byte pad = (byte) (msb < 0 ? 0xFF : 0x00); PlatformDependent.setMemory(outAddress + length, DecimalVector.TYPE_WIDTH - length, pad); } }
From source file:org.apache.arrow.vector.util.ByteFunctionHelpers.java
License:Apache License
private static final int memEqual(final long laddr, int lStart, int lEnd, final long raddr, int rStart, final int rEnd) { int n = lEnd - lStart; if (n == rEnd - rStart) { long lPos = laddr + lStart; long rPos = raddr + rStart; while (n > 7) { long leftLong = PlatformDependent.getLong(lPos); long rightLong = PlatformDependent.getLong(rPos); if (leftLong != rightLong) { return 0; }//from w w w .j a va 2 s . co m lPos += 8; rPos += 8; n -= 8; } while (n-- != 0) { byte leftByte = PlatformDependent.getByte(lPos); byte rightByte = PlatformDependent.getByte(rPos); if (leftByte != rightByte) { return 0; } lPos++; rPos++; } return 1; } else { return 0; } }
From source file:org.apache.arrow.vector.util.ByteFunctionHelpers.java
License:Apache License
private static final int memcmp(final long laddr, int lStart, int lEnd, final long raddr, int rStart, final int rEnd) { int lLen = lEnd - lStart; int rLen = rEnd - rStart; int n = Math.min(rLen, lLen); long lPos = laddr + lStart; long rPos = raddr + rStart; while (n > 7) { long leftLong = PlatformDependent.getLong(lPos); long rightLong = PlatformDependent.getLong(rPos); if (leftLong != rightLong) { return UnsignedLongs.compare(Long.reverseBytes(leftLong), Long.reverseBytes(rightLong)); }/*from w w w . jav a2 s. c o m*/ lPos += 8; rPos += 8; n -= 8; } while (n-- != 0) { byte leftByte = PlatformDependent.getByte(lPos); byte rightByte = PlatformDependent.getByte(rPos); if (leftByte != rightByte) { return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1; } lPos++; rPos++; } if (lLen == rLen) { return 0; } return lLen > rLen ? 1 : -1; }
From source file:org.apache.arrow.vector.util.ByteFunctionHelpers.java
License:Apache License
private static final int memcmp(final long laddr, int lStart, int lEnd, final byte[] right, int rStart, final int rEnd) { int lLen = lEnd - lStart; int rLen = rEnd - rStart; int n = Math.min(rLen, lLen); long lPos = laddr + lStart; int rPos = rStart; while (n-- != 0) { byte leftByte = PlatformDependent.getByte(lPos); byte rightByte = right[rPos]; if (leftByte != rightByte) { return ((leftByte & 0xFF) - (rightByte & 0xFF)) > 0 ? 1 : -1; }/*from ww w. j av a 2s . com*/ lPos++; rPos++; } if (lLen == rLen) { return 0; } return lLen > rLen ? 1 : -1; }
From source file:org.apache.drill.exec.expr.fn.impl.DrillHash.java
License:Apache License
public static final long getLongLittleEndian(long offset) { //return PlatformDependent.getLong(offset); return ((long) PlatformDependent.getByte(offset + 7) << 56) | ((PlatformDependent.getByte(offset + 6) & 0xffL) << 48) | ((PlatformDependent.getByte(offset + 5) & 0xffL) << 40) | ((PlatformDependent.getByte(offset + 4) & 0xffL) << 32) | ((PlatformDependent.getByte(offset + 3) & 0xffL) << 24) | ((PlatformDependent.getByte(offset + 2) & 0xffL) << 16) | ((PlatformDependent.getByte(offset + 1) & 0xffL) << 8) | ((PlatformDependent.getByte(offset) & 0xffL)); }
From source file:org.apache.drill.exec.expr.fn.impl.DrillHash.java
License:Apache License
public static final long getIntLittleEndian(long offset) { long retl = 0; retl = ((PlatformDependent.getByte(offset + 3) & 0xffL) << 24) | ((PlatformDependent.getByte(offset + 2) & 0xffL) << 16) | ((PlatformDependent.getByte(offset + 1) & 0xffL) << 8) | ((PlatformDependent.getByte(offset) & 0xffL)); return retl;/*from w w w. j av a 2s .co m*/ }
From source file:org.apache.drill.exec.expr.fn.impl.MurmurHash3.java
License:Apache License
public static long murmur3_64(long bStart, long bEnd, DrillBuf buffer, int seed) { long h1 = seed & 0x00000000FFFFFFFFL; long h2 = seed & 0x00000000FFFFFFFFL; final long c1 = 0x87c37b91114253d5L; final long c2 = 0x4cf5ad432745937fL; long start = buffer.memoryAddress() + bStart; long end = buffer.memoryAddress() + bEnd; long length = bEnd - bStart; long roundedEnd = start + (length & 0xFFFFFFF0); // round down to 16 byte block for (long i = start; i < roundedEnd; i += 16) { long k1 = getLongLittleEndian(i); long k2 = getLongLittleEndian(i + 8); k1 *= c1;//w ww . j av a 2s. c o m k1 = Long.rotateLeft(k1, 31); k1 *= c2; h1 ^= k1; h1 = Long.rotateLeft(h1, 27); h1 += h2; h1 = h1 * 5 + 0x52dce729; k2 *= c2; k2 = Long.rotateLeft(k2, 33); k2 *= c1; h2 ^= k2; h2 = Long.rotateLeft(h2, 31); h2 += h1; h2 = h2 * 5 + 0x38495ab5; } long k1 = 0; long k2 = 0; // tail switch ((int) length & 15) { case 15: k2 = (PlatformDependent.getByte(roundedEnd + 14) & 0xffL) << 48; case 14: k2 ^= (PlatformDependent.getByte(roundedEnd + 13) & 0xffL) << 40; case 13: k2 ^= (PlatformDependent.getByte(roundedEnd + 12) & 0xffL) << 32; case 12: k2 ^= (PlatformDependent.getByte(roundedEnd + 11) & 0xffL) << 24; case 11: k2 ^= (PlatformDependent.getByte(roundedEnd + 10) & 0xffL) << 16; case 10: k2 ^= (PlatformDependent.getByte(roundedEnd + 9) & 0xffL) << 8; case 9: k2 ^= (PlatformDependent.getByte(roundedEnd + 8) & 0xffL); k2 *= c2; k2 = Long.rotateLeft(k2, 33); k2 *= c1; h2 ^= k2; case 8: k1 = (long) PlatformDependent.getByte(roundedEnd + 7) << 56; case 7: k1 ^= (PlatformDependent.getByte(roundedEnd + 6) & 0xffL) << 48; case 6: k1 ^= (PlatformDependent.getByte(roundedEnd + 5) & 0xffL) << 40; case 5: k1 ^= (PlatformDependent.getByte(roundedEnd + 4) & 0xffL) << 32; case 4: k1 ^= (PlatformDependent.getByte(roundedEnd + 3) & 0xffL) << 24; case 3: k1 ^= (PlatformDependent.getByte(roundedEnd + 2) & 0xffL) << 16; case 2: k1 ^= (PlatformDependent.getByte(roundedEnd + 1) & 0xffL) << 8; case 1: k1 ^= (PlatformDependent.getByte(roundedEnd) & 0xffL); k1 *= c1; k1 = Long.rotateLeft(k1, 31); k1 *= c2; h1 ^= k1; } h1 ^= length; h2 ^= length; h1 += h2; h2 += h1; h1 = fmix64(h1); h2 = fmix64(h2); h1 += h2; h2 += h1; // murmur3_128 should return 128 bit (h1,h2), now we return only 64bits, return h1; }