/** * Returns the hash code of bytes of the wild memory from the given address. Use with caution. * * <p>Default implementation delegates to {@link #hash(Object, Access, long, long)} method * using {@linkplain Access#unsafe() unsafe} {@code Access}. * * @param address the address of the first byte to hash * @param len length of the byte sequence to hash * @return hash code for the specified byte sequence */ public long hashMemory(long address, long len) { return unsafeHash(null, address, len); }
/** * Shortcut for {@link #hashChars(char[], int, int) hashChars(input, 0, input.length)}. */ public long hashChars(@NotNull char[] input) { return unsafeHash(input, CHAR_BASE, input.length * 2L); }
/** * Shortcut for {@link #hashShorts(short[], int, int) hashShorts(input, 0, input.length)}. */ public long hashShorts(@NotNull short[] input) { return unsafeHash(input, SHORT_BASE, input.length * 2L); }
/** * Shortcut for {@link #hashBytes(byte[], int, int) hashBytes(input, 0, input.length)}. */ public long hashBytes(@NotNull byte[] input) { return unsafeHash(input, BYTE_BASE, input.length); }
/** * Shortcut for {@link #hashLongs(long[], int, int) hashLongs(input, 0, input.length)}. */ public long hashLongs(@NotNull long[] input) { return unsafeHash(input, LONG_BASE, input.length * 8L); }
/** * Shortcut for {@link #hashBooleans(boolean[], int, int) hashBooleans(input, 0, input.length)}. */ public long hashBooleans(@NotNull boolean[] input) { return unsafeHash(input, BOOLEAN_BASE, input.length); }
/** * Shortcut for {@link #hashInts(int[], int, int) hashInts(input, 0, input.length)}. */ public long hashInts(@NotNull int[] input) { return unsafeHash(input, INT_BASE, input.length * 4L); }
private long hashByteBuffer(@NotNull ByteBuffer input, int off, int len) { if (input.hasArray()) { return unsafeHash(input.array(), BYTE_BASE + input.arrayOffset() + off, len); } else if (input instanceof DirectBuffer) { return unsafeHash(null, ((DirectBuffer) input).address() + off, len); } else { return hash(input, ByteBufferAccess.INSTANCE, off, len); } }
/** * Returns the hash code for the specified subsequence of the given {@code boolean} array. * * <p>Default implementation delegates to {@link #hash(Object, Access, long, long)} method * using {@linkplain Access#unsafe() unsafe} {@code Access}. * * @param input the array to read data from * @param off index of the first {@code boolean} in the subsequence to hash * @param len length of the subsequence to hash * @return hash code for the specified subsequence * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > input.length} * or {@code len < 0} */ public long hashBooleans(@NotNull boolean[] input, int off, int len) { checkArrayOffs(input.length, off, len); return unsafeHash(input, BOOLEAN_BASE + off, len); }
/** * Returns the hash code for the specified subsequence of the given {@code byte} array. * * <p>Default implementation delegates to {@link #hash(Object, Access, long, long)} method * using {@linkplain Access#unsafe() unsafe} {@code Access}. * * @param input the array to read bytes from * @param off index of the first {@code byte} in the subsequence to hash * @param len length of the subsequence to hash * @return hash code for the specified subsequence * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > input.length} * or {@code len < 0} */ public long hashBytes(@NotNull byte[] input, int off, int len) { checkArrayOffs(input.length, off, len); return unsafeHash(input, BYTE_BASE + off, len); }
/** * Returns the hash code for bytes, as they lay in memory, of the specified subsequence * of the given {@code short} array. * * <p>Default implementation delegates to {@link #hash(Object, Access, long, long)} method * using {@linkplain Access#unsafe() unsafe} {@code Access}. * * @param input the array to read data from * @param off index of the first {@code short} in the subsequence to hash * @param len length of the subsequence to hash, in shorts (i. e. the length of the bytes * sequence to hash is {@code len * 2L}) * @return hash code for the specified subsequence * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > input.length} * or {@code len < 0} */ public long hashShorts(@NotNull short[] input, int off, int len) { checkArrayOffs(input.length, off, len); return unsafeHash(input, SHORT_BASE + (off * 2L), len * 2L); }
/** * Returns the hash code for bytes, as they lay in memory, of the specified subsequence * of the given {@code long} array. * * <p>Default implementation delegates to {@link #hash(Object, Access, long, long)} method * using {@linkplain Access#unsafe() unsafe} {@code Access}. * * @param input the array to read data from * @param off index of the first {@code long} in the subsequence to hash * @param len length of the subsequence to hash, in longs (i. e. the length of the bytes * sequence to hash is {@code len * 8L}) * @return hash code for the specified subsequence * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > input.length} * or {@code len < 0} */ public long hashLongs(@NotNull long[] input, int off, int len) { checkArrayOffs(input.length, off, len); return unsafeHash(input, LONG_BASE + (off * 8L), len * 8L); } }
/** * Returns the hash code for bytes, as they lay in memory, of the specified subsequence * of the given {@code char} array. * * <p>Default implementation delegates to {@link #hash(Object, Access, long, long)} method * using {@linkplain Access#unsafe() unsafe} {@code Access}. * * @param input the array to read data from * @param off index of the first {@code char} in the subsequence to hash * @param len length of the subsequence to hash, in chars (i. e. the length of the bytes * sequence to hash is {@code len * 2L}) * @return hash code for the specified subsequence * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > input.length} * or {@code len < 0} */ public long hashChars(@NotNull char[] input, int off, int len) { checkArrayOffs(input.length, off, len); return unsafeHash(input, CHAR_BASE + (off * 2L), len * 2L); }
/** * Returns the hash code for bytes, as they lay in memory, of the specified subsequence * of the given {@code int} array. * * <p>Default implementation delegates to {@link #hash(Object, Access, long, long)} method * using {@linkplain Access#unsafe() unsafe} {@code Access}. * * @param input the array to read data from * @param off index of the first {@code int} in the subsequence to hash * @param len length of the subsequence to hash, in ints (i. e. the length of the bytes * sequence to hash is {@code len * 4L}) * @return hash code for the specified subsequence * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > input.length} * or {@code len < 0} */ public long hashInts(@NotNull int[] input, int off, int len) { checkArrayOffs(input.length, off, len); return unsafeHash(input, INT_BASE + (off * 4L), len * 4L); }