@Override public boolean equivalent(RandomDataInput source, long sourceOffset) { return source.readInt(sourceOffset) == instance; }
@Override public boolean equivalent(RandomDataInput source, long sourceOffset) { return source.readInt(sourceOffset) == instance; }
@Override default int readInt(S handle, long offset) { return handle.readInt(offset); }
@Override default int readInt(S handle, long offset) { return handle.readInt(offset); }
/** * Read an unsigned int at an offset * * @param offset to read * @return the unsigned int * @throws BufferUnderflowException if the offset is outside the limits of the Bytes */ @ForceInline default long readUnsignedInt(long offset) throws BufferUnderflowException { return readInt(offset) & 0xFFFFFFFFL; }
default int fastHash(long offset, int length) throws BufferUnderflowException { long hash = 0; int i = 0; if (length >= 4) { hash = readInt(offset + i); i += 4; } for (; i < length - 3; i += 4) { hash *= 0x6d0f27bd; hash += readInt(offset + i); } if (i < length - 1) { hash *= 0x6d0f27bdL; hash += readShort(offset + i); i += 2; } if (i < length) hash += readByte(offset + i); hash *= 0x855dd4db; return (int) (hash ^ (hash >> 32)); } }
/** * Read a long which is zero padded (high bytes) if the available bytes is less than 8. * If the offset is at or beyond the readLimit, this will return 0L. * * @param offset to read from * @return the long which might be padded. */ default long readIncompleteLong(long offset) { long left = readLimit() - offset; long l; try { if (left >= 8) return readLong(offset); if (left == 4) return readInt(offset); l = 0; for (int i = 0, remaining = (int) left; i < remaining; i++) { l |= (long) readUnsignedByte(offset + i) << (i * 8); } } catch (BufferUnderflowException e) { throw new AssertionError(e); } return l; }
public static void writeFully(@org.jetbrains.annotations.NotNull @NotNull RandomDataInput bytes, long offset, long length, @org.jetbrains.annotations.NotNull StreamingDataOutput sdo) throws BufferUnderflowException, BufferOverflowException { long i = 0; for (; i < length - 7; i += 8) sdo.writeLong(bytes.readLong(offset + i)); if (i < length - 3) { sdo.writeInt(bytes.readInt(offset + i)); i += 4; } for (; i < length; i++) sdo.writeByte(bytes.readByte(offset + i)); }
public static boolean bytesEqual( @org.jetbrains.annotations.NotNull @NotNull RandomDataInput a, long offset, @org.jetbrains.annotations.NotNull @NotNull RandomDataInput second, long secondOffset, long len) throws BufferUnderflowException { long i = 0; while (len - i >= 8L) { if (a.readLong(offset + i) != second.readLong(secondOffset + i)) return false; i += 8L; } if (len - i >= 4L) { if (a.readInt(offset + i) != second.readInt(secondOffset + i)) return false; i += 4L; } if (len - i >= 2L) { if (a.readShort(offset + i) != second.readShort(secondOffset + i)) return false; i += 2L; } if (i < len) return a.readByte(offset + i) == second.readByte(secondOffset + i); return true; }