@Override boolean advanceWithinBlock(IndexedDISI disi, int target) throws IOException { final int targetInBlock = target & 0xFFFF; // TODO: binary search for (; disi.index < disi.nextBlockIndex;) { int doc = Short.toUnsignedInt(disi.slice.readShort()); disi.index++; if (doc >= targetInBlock) { disi.doc = disi.block | doc; disi.exists = true; return true; } } return false; } @Override
private void readBlockHeader() throws IOException { block = Short.toUnsignedInt(slice.readShort()) << 16; assert block >= 0; final int numValues = 1 + Short.toUnsignedInt(slice.readShort()); index = nextBlockIndex; nextBlockIndex = index + numValues; if (numValues <= MAX_ARRAY_LENGTH) { method = Method.SPARSE; blockEnd = slice.getFilePointer() + (numValues << 1); } else if (numValues == 65536) { method = Method.ALL; blockEnd = slice.getFilePointer(); gap = block - index - 1; } else { method = Method.DENSE; blockEnd = slice.getFilePointer() + (1 << 13); wordIndex = -1; numberOfOnes = index + 1; } }
@Override boolean advanceExactWithinBlock(IndexedDISI disi, int target) throws IOException { final int targetInBlock = target & 0xFFFF; // TODO: binary search if (target == disi.doc) { return disi.exists; } for (; disi.index < disi.nextBlockIndex;) { int doc = Short.toUnsignedInt(disi.slice.readShort()); disi.index++; if (doc >= targetInBlock) { if (doc != targetInBlock) { disi.index--; disi.slice.seek(disi.slice.getFilePointer() - Short.BYTES); break; } disi.exists = true; return true; } } disi.exists = false; return false; } },
private static void readInts24(IndexInput in, int count, int[] docIDs) throws IOException { int i; for (i = 0; i < count - 7; i += 8) { long l1 = in.readLong(); long l2 = in.readLong(); long l3 = in.readLong(); docIDs[i] = (int) (l1 >>> 40); docIDs[i+1] = (int) (l1 >>> 16) & 0xffffff; docIDs[i+2] = (int) (((l1 & 0xffff) << 8) | (l2 >>> 56)); docIDs[i+3] = (int) (l2 >>> 32) & 0xffffff; docIDs[i+4] = (int) (l2 >>> 8) & 0xffffff; docIDs[i+5] = (int) (((l2 & 0xff) << 16) | (l3 >>> 48)); docIDs[i+6] = (int) (l3 >>> 24) & 0xffffff; docIDs[i+7] = (int) l3 & 0xffffff; } for (; i < count; ++i) { docIDs[i] = (Short.toUnsignedInt(in.readShort()) << 8) | Byte.toUnsignedInt(in.readByte()); } }
@Test public void testEditHeaders() { ByteBuffer buffer = createMockHeaders(); UDPHeader header = new UDPHeader(buffer); header.setSourcePort(1111); header.setDestinationPort(2222); header.setPayloadLength(34); Assert.assertEquals(1111, header.getSourcePort()); Assert.assertEquals(2222, header.getDestinationPort()); // assert the buffer has been modified int sourcePort = Short.toUnsignedInt(buffer.getShort(0)); int destinationPort = Short.toUnsignedInt(buffer.getShort(2)); int length = Short.toUnsignedInt(buffer.getShort(4)); Assert.assertEquals(1111, sourcePort); Assert.assertEquals(2222, destinationPort); Assert.assertEquals(42, length); header.swapSourceAndDestination(); Assert.assertEquals(2222, header.getSourcePort()); Assert.assertEquals(1111, header.getDestinationPort()); sourcePort = Short.toUnsignedInt(buffer.getShort(0)); destinationPort = Short.toUnsignedInt(buffer.getShort(2)); Assert.assertEquals(2222, sourcePort); Assert.assertEquals(1111, destinationPort); }
int sourcePort = Short.toUnsignedInt(buffer.getShort(0)); int destinationPort = Short.toUnsignedInt(buffer.getShort(2)); int sequenceNumber = buffer.getInt(4); int acknowledgementNumber = buffer.getInt(8); Assert.assertEquals(1111, header.getDestinationPort()); sourcePort = Short.toUnsignedInt(buffer.getShort(0)); destinationPort = Short.toUnsignedInt(buffer.getShort(2));
Assert.assertEquals(0x1122, Short.toUnsignedInt(packetPayload.getShort()));
private static void readInts24(IndexInput in, int count, IntersectVisitor visitor) throws IOException { int i; for (i = 0; i < count - 7; i += 8) { long l1 = in.readLong(); long l2 = in.readLong(); long l3 = in.readLong(); visitor.visit((int) (l1 >>> 40)); visitor.visit((int) (l1 >>> 16) & 0xffffff); visitor.visit((int) (((l1 & 0xffff) << 8) | (l2 >>> 56))); visitor.visit((int) (l2 >>> 32) & 0xffffff); visitor.visit((int) (l2 >>> 8) & 0xffffff); visitor.visit((int) (((l2 & 0xff) << 16) | (l3 >>> 48))); visitor.visit((int) (l3 >>> 24) & 0xffffff); visitor.visit((int) l3 & 0xffffff); } for (; i < count; ++i) { visitor.visit((Short.toUnsignedInt(in.readShort()) << 8) | Byte.toUnsignedInt(in.readByte())); } } }
@Test public void testEditHeaders() { ByteBuffer buffer = createMockHeaders(); IPv4Header header = new IPv4Header(buffer); header.setSource(0x87654321); header.setDestination(0x24242424); header.setTotalLength(42); Assert.assertEquals(0x87654321, header.getSource()); Assert.assertEquals(0x24242424, header.getDestination()); Assert.assertEquals(42, header.getTotalLength()); // assert the buffer has been modified int source = buffer.getInt(12); int destination = buffer.getInt(16); int totalLength = Short.toUnsignedInt(buffer.getShort(2)); Assert.assertEquals(0x87654321, source); Assert.assertEquals(0x24242424, destination); Assert.assertEquals(42, totalLength); header.swapSourceAndDestination(); Assert.assertEquals(0x24242424, header.getSource()); Assert.assertEquals(0x87654321, header.getDestination()); source = buffer.getInt(12); destination = buffer.getInt(16); Assert.assertEquals(0x24242424, source); Assert.assertEquals(0x87654321, destination); }
@Test public void testParseHeaders() { ByteBuffer buffer = createMockPacket(); IPv4Packet packet = new IPv4Packet(buffer); IPv4Header ipv4Header = packet.getIpv4Header(); Assert.assertTrue(ipv4Header.isSupported()); Assert.assertEquals(20, ipv4Header.getHeaderLength()); Assert.assertEquals(32, ipv4Header.getTotalLength()); Assert.assertEquals(IPv4Header.Protocol.UDP, ipv4Header.getProtocol()); Assert.assertEquals(0x12345678, ipv4Header.getSource()); Assert.assertEquals(0x42424242, ipv4Header.getDestination()); UDPHeader udpHeader = (UDPHeader) packet.getTransportHeader(); Assert.assertEquals(1234, udpHeader.getSourcePort()); Assert.assertEquals(5678, udpHeader.getDestinationPort()); Assert.assertEquals(8, udpHeader.getHeaderLength()); packet.swapSourceAndDestination(); Assert.assertEquals(0x42424242, ipv4Header.getSource()); Assert.assertEquals(0x12345678, ipv4Header.getDestination()); Assert.assertEquals(5678, udpHeader.getSourcePort()); Assert.assertEquals(1234, udpHeader.getDestinationPort()); int source = buffer.getInt(12); int destination = buffer.getInt(16); int sourcePort = Short.toUnsignedInt(buffer.getShort(20)); int destinationPort = Short.toUnsignedInt(buffer.getShort(22)); Assert.assertEquals(0x42424242, source); Assert.assertEquals(0x12345678, destination); Assert.assertEquals(5678, sourcePort); Assert.assertEquals(1234, destinationPort); }
final int seedHash = Short.toUnsignedInt(computeSeedHash(seed)); final double errConst = mergeFlag ? log(2) : sqrt(log(2) / 2.0); final double rse = errConst / Math.sqrt(1 << lgK);
@Override public String toString() { final int seedHash = Short.toUnsignedInt(getSeedHash()); final StringBuilder sb = new StringBuilder(); sb.append("### ").append(this.getClass().getSimpleName()).append(" SUMMARY: ").append(LS); sb.append(" Estimate : ").append(getEstimate()).append(LS); sb.append(" Upper Bound, 95% conf : ").append(getUpperBound(2)).append(LS); sb.append(" Lower Bound, 95% conf : ").append(getLowerBound(2)).append(LS); sb.append(" Theta (double) : ").append(getTheta()).append(LS); sb.append(" Theta (long) : ").append(getThetaLong()).append(LS); sb.append(" EstMode? : ").append(isEstimationMode()).append(LS); sb.append(" Empty? : ").append(isEmpty()).append(LS); sb.append(" Retained Entries : ").append(getRetainedEntries()).append(LS); if (this instanceof ArrayOfDoublesUpdatableSketch) { final ArrayOfDoublesUpdatableSketch updatable = (ArrayOfDoublesUpdatableSketch) this; sb.append(" Nominal Entries (k) : ").append(updatable.getNominalEntries()).append(LS); sb.append(" Current Capacity : ").append(updatable.getCurrentCapacity()).append(LS); sb.append(" Resize Factor : ").append(updatable.getResizeFactor().getValue()).append(LS); sb.append(" Sampling Probability (p): ").append(updatable.getSamplingProbability()).append(LS); } sb.append(" Seed Hash : ") .append(Integer.toHexString(seedHash)).append(" | ").append(seedHash).append(LS); sb.append("### END SKETCH SUMMARY").append(LS); return sb.toString(); }
final String thetaHex = zeroPad(Long.toHexString(thetaLong), 16); final String thisSimpleName = this.getClass().getSimpleName(); final int seedHash = Short.toUnsignedInt(getSeedHash());
AbstractVersionException(final String message, final short version, final ABIVersion closestVersion) { super(message); this.closestVersion = Preconditions.checkNotNull(closestVersion); this.version = Short.toUnsignedInt(version); }
@Override public void copy(long offsetAddr, int count) { dst.allocateNew(); final long max = offsetAddr + count * STEP_SIZE; int target = 0; for(long addr = offsetAddr; addr < max; addr += STEP_SIZE) { int index = Short.toUnsignedInt(PlatformDependent.getShort(addr)); transfer.copyValueSafe(index, target); target++; } }
/** * {@inheritDoc} */ @Override public List<String> get_partition_names(final String dbName, final String tblName, final short maxParts) throws TException { final String databaseName = normalizeIdentifier(dbName); final String tableName = normalizeIdentifier(tblName); final Integer maxValues = maxParts > 0 ? Short.toUnsignedInt(maxParts) : null; return requestWrapper("get_partition_names", new Object[]{databaseName, tableName, maxParts}, () -> partV1 .getPartitionKeys(catalogName, databaseName, tableName, null, null, null, null, maxValues)); }
@Override public void copy(long offsetAddr, int count) { dst.allocateNew(); final long max = offsetAddr + count * BUILD_RECORD_LINK_SIZE; int target = 0; for(long addr = offsetAddr; addr < max; addr += BUILD_RECORD_LINK_SIZE) { final int batchIndex = PlatformDependent.getInt(addr); final int batchOffset = Short.toUnsignedInt(PlatformDependent.getShort(addr + 4)); transfer[batchIndex].copyValueSafe(batchOffset, target); target++; } }
@Override public void copy(long offsetAddr, int count) { targetAlt.allocateNew(count); final long max = offsetAddr + count * STEP_SIZE; long srcAddr = source.getDataBufferAddress(); long dstAddr = target.getDataBufferAddress(); for(long addr = offsetAddr; addr < max; addr += STEP_SIZE, dstAddr += SIZE){ PlatformDependent.putLong(dstAddr, PlatformDependent.getLong(srcAddr + Short.toUnsignedInt(PlatformDependent.getShort(addr)) * SIZE)); } }
@Override public void copy(long offsetAddr, int count) { targetAlt.allocateNew(count); final long max = offsetAddr + count * STEP_SIZE; final long srcAddr = source.getDataBufferAddress(); long dstAddr = target.getDataBufferAddress(); for(long addr = offsetAddr; addr < max; addr += STEP_SIZE, dstAddr += SIZE){ PlatformDependent.putInt(dstAddr, PlatformDependent.getInt(srcAddr + Short.toUnsignedInt(PlatformDependent.getShort(addr)) * SIZE)); } }
@Override public void copy(long offsetAddr, int count) { targetAlt.allocateNew(count); final long max = offsetAddr + count * STEP_SIZE; final long srcAddr = source.getDataBufferAddress(); long dstAddr = target.getDataBufferAddress(); for(long addr = offsetAddr; addr < max; addr += STEP_SIZE, dstAddr += SIZE){ final int offset = Short.toUnsignedInt(PlatformDependent.getShort(addr)) * SIZE; PlatformDependent.putLong(dstAddr, PlatformDependent.getLong(srcAddr + offset)); PlatformDependent.putLong(dstAddr+8, PlatformDependent.getLong(srcAddr + + offset + 8)); } }