static int computePosition(long hashcode, int hashTableSize) { return (int) ((Integer.toUnsignedLong(Long.hashCode(hashcode)) * hashTableSize) >> 32); } }
static int computePosition(long hashcode, int hashTableSize) { return (int) ((Integer.toUnsignedLong(Long.hashCode(hashcode)) * hashTableSize) >> 32); } }
public void setValue(long value) { if (value >= 0L) { bigInteger = BigInteger.valueOf(value); } else { int upper = (int) (value >>> 32); int lower = (int) value; bigInteger = BigInteger .valueOf(Integer.toUnsignedLong(upper)) .shiftLeft(32) .add(BigInteger.valueOf(Integer.toUnsignedLong(lower))); } }
@Override public long getTransactionId() { return Integer.toUnsignedLong(rawMessage.getTransactionId()); }
@Benchmark public long computePositionWithBitShifting() { return (int) ((Integer.toUnsignedLong(Long.hashCode(hashcode)) * hashTableSize) >> 32); }
@Benchmark public long computePositionWithDivision() { return (int) ((Integer.toUnsignedLong(Long.hashCode(hashcode)) * hashTableSize) / (1 << 32)); }
private void testSetUnsignedInt(Buffer buff) throws Exception { for (int i = 0; i < numSets; i++) { long val = Integer.toUnsignedLong(Integer.MAX_VALUE + i); buff.setUnsignedInt(i * 4, val); } for (int i = 0; i < numSets; i++) { long val = Integer.toUnsignedLong(Integer.MAX_VALUE + i); assertEquals(val, buff.getUnsignedInt(i * 4)); } }
@Override public void processMessage(final ByteBuffer buffer, ReplicationMessageProcessor processor, TypeRegistry typeRegistry) throws SQLException, InterruptedException { try { if (!buffer.hasArray()) { throw new IllegalStateException( "Invalid buffer received from PG server during streaming replication"); } final byte[] source = buffer.array(); final byte[] content = Arrays.copyOfRange(source, buffer.arrayOffset(), source.length); final RowMessage message = PgProto.RowMessage.parseFrom(content); if (!message.getNewTypeinfoList().isEmpty() && message.getNewTupleCount() != message.getNewTypeinfoCount()) { throw new ConnectException(String.format("Message from transaction {} has {} data columns but only {} of type info", Integer.toUnsignedLong(message.getTransactionId()), message.getNewTupleCount(), message.getNewTypeinfoCount())); } processor.process(new PgProtoReplicationMessage(message, typeRegistry)); } catch (InvalidProtocolBufferException e) { throw new ConnectException(e); } }
private void testGetSetUnsignedInt(boolean isLE) throws Exception { int numInts = 100; Buffer b = Buffer.buffer(numInts * 4); for (int i = 0; i < numInts; i++) { if (isLE) { b.setUnsignedIntLE(i * 4, (int) (Integer.MAX_VALUE + (long) i)); } else { b.setUnsignedInt(i * 4, (int) (Integer.MAX_VALUE + (long) i)); } } for (int i = 0; i < numInts; i++) { if (isLE) { assertEquals(Integer.toUnsignedLong(Integer.MAX_VALUE + i), b.getUnsignedIntLE(i * 4)); } else { assertEquals(Integer.toUnsignedLong(Integer.MAX_VALUE + i), b.getUnsignedInt(i * 4)); } } }
private void testGetSetUnsignedMedium(boolean isLE) throws Exception { int numInts = 100; int MEDIUM_MAX_VALUE = BufferTest.MEDIUM_MAX_VALUE - numInts; Buffer b = Buffer.buffer(numInts * 3); for (int i = 0; i < numInts; i++) { if (isLE) { b.setMediumLE(i * 3, (MEDIUM_MAX_VALUE + i)); } else { b.setMedium(i * 3, (MEDIUM_MAX_VALUE + i)); } } for (int i = 0; i < numInts; i++) { if (isLE) { assertEquals(Integer.toUnsignedLong(MEDIUM_MAX_VALUE + i), b.getUnsignedMediumLE(i * 3)); } else { assertEquals(Integer.toUnsignedLong(MEDIUM_MAX_VALUE + i), b.getUnsignedMedium(i * 3)); } } }
private void testGetSetUnsignedShort(boolean isLE) throws Exception { int numShorts = 100; Buffer b = Buffer.buffer(numShorts * 2); for (short i = 0; i < numShorts; i++) { if (isLE) { b.setUnsignedShortLE(i * 2, (short) (Short.MAX_VALUE + (int) i)); } else { b.setUnsignedShort(i * 2, (short) (Short.MAX_VALUE + (int) i)); } } for (short i = 0; i < numShorts; i++) { if (isLE) { assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShortLE(i * 2)); } else { assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShort(i * 2)); } } }
/** Check whether the given point is within the considered polygon. * NOTE: this operates directly on the encoded representation of points. */ public boolean test(int lat, int lon) { final int lat2 = ((lat - Integer.MIN_VALUE) >>> latShift); if (lat2 < latBase || lat2 >= latBase + maxLatDelta) { return false; } int lon2 = ((lon - Integer.MIN_VALUE) >>> lonShift); if (lon2 < lonBase) { // wrap lon2 += 1 << (32 - lonShift); } assert Integer.toUnsignedLong(lon2) >= lonBase; assert lon2 - lonBase >= 0; if (lon2 - lonBase >= maxLonDelta) { return false; } final int relation = relations[(lat2 - latBase) * maxLonDelta + (lon2 - lonBase)]; if (relation == Relation.CELL_CROSSES_QUERY.ordinal()) { return tree.contains(decodeLatitude(lat), decodeLongitude(lon)); } else { return relation == Relation.CELL_INSIDE_QUERY.ordinal(); } } }
/** Check whether the given point is within a distance of another point. * NOTE: this operates directly on the encoded representation of points. */ public boolean test(int lat, int lon) { final int lat2 = ((lat - Integer.MIN_VALUE) >>> latShift); if (lat2 < latBase || lat2 >= latBase + maxLatDelta) { return false; } int lon2 = ((lon - Integer.MIN_VALUE) >>> lonShift); if (lon2 < lonBase) { // wrap lon2 += 1 << (32 - lonShift); } assert Integer.toUnsignedLong(lon2) >= lonBase; assert lon2 - lonBase >= 0; if (lon2 - lonBase >= maxLonDelta) { return false; } final int relation = relations[(lat2 - latBase) * maxLonDelta + (lon2 - lonBase)]; if (relation == Relation.CELL_CROSSES_QUERY.ordinal()) { return SloppyMath.haversinSortKey( decodeLatitude(lat), decodeLongitude(lon), this.lat, this.lon) <= distanceKey; } else { return relation == Relation.CELL_INSIDE_QUERY.ordinal(); } } }
long max = 0; for (int i = 0; i < count; ++i) { max |= Integer.toUnsignedLong(docIds[start + i]);
public static long encodeLatLon(double lat, double lon) { return (Integer.toUnsignedLong(GeoEncodingUtils.encodeLatitude(lat)) << 32) | Integer.toUnsignedLong(GeoEncodingUtils.encodeLongitude(lon)); }
long l = Integer.toUnsignedLong(uint); System.out.println(l); // will print 4294967295 int x = Integer.parseUnsignedInt("4294967295"); int y = 5; int cmp1 = Integer.compareUnsigned(x,y); // interprets x as 4294967295 (x>y) int cmp2 = Integer.compare(x,y); // interprets x as -1 (x<y)
static void verifyChecksum(BufferedChecksumStreamInput in) throws IOException { // This absolutely must come first, or else reading the checksum becomes part of the checksum long expectedChecksum = in.getChecksum(); long readChecksum = Integer.toUnsignedLong(in.readInt()); if (readChecksum != expectedChecksum) { throw new TranslogCorruptedException(in.getSource(), "checksum verification failed - expected: 0x" + Long.toHexString(expectedChecksum) + ", got: 0x" + Long.toHexString(readChecksum)); } }
private void testSetUnsignedInt(Buffer buff) throws Exception { for (int i = 0; i < numSets; i++) { long val = Integer.toUnsignedLong(Integer.MAX_VALUE + i); buff.setUnsignedInt(i * 4, val); } for (int i = 0; i < numSets; i++) { long val = Integer.toUnsignedLong(Integer.MAX_VALUE + i); assertEquals(val, buff.getUnsignedInt(i * 4)); } }
private void testGetSetUnsignedShort(boolean isLE) throws Exception { int numShorts = 100; Buffer b = Buffer.buffer(numShorts * 2); for (short i = 0; i < numShorts; i++) { if (isLE) { b.setUnsignedShortLE(i * 2, (short) (Short.MAX_VALUE + (int) i)); } else { b.setUnsignedShort(i * 2, (short) (Short.MAX_VALUE + (int) i)); } } for (short i = 0; i < numShorts; i++) { if (isLE) { assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShortLE(i * 2)); } else { assertEquals(Integer.toUnsignedLong(Short.MAX_VALUE + i), b.getUnsignedShort(i * 2)); } } }
private void testGetSetUnsignedInt(boolean isLE) throws Exception { int numInts = 100; Buffer b = Buffer.buffer(numInts * 4); for (int i = 0; i < numInts; i++) { if (isLE) { b.setUnsignedIntLE(i * 4, (int) (Integer.MAX_VALUE + (long) i)); } else { b.setUnsignedInt(i * 4, (int) (Integer.MAX_VALUE + (long) i)); } } for (int i = 0; i < numInts; i++) { if (isLE) { assertEquals(Integer.toUnsignedLong(Integer.MAX_VALUE + i), b.getUnsignedIntLE(i * 4)); } else { assertEquals(Integer.toUnsignedLong(Integer.MAX_VALUE + i), b.getUnsignedInt(i * 4)); } } }