Package com.scurrilous.circe.impl
Class IntStatefulLongHash
- java.lang.Object
-
- com.scurrilous.circe.impl.IntStatefulLongHash
-
- All Implemented Interfaces:
Hash,StatefulHash,StatefulLongHash
public final class IntStatefulLongHash extends java.lang.Object implements StatefulLongHash
Promotes aStatefulIntHashto aStatefulLongHash.
-
-
Constructor Summary
Constructors Constructor Description IntStatefulLongHash(StatefulIntHash intHash)Constructs a newIntStatefulLongHashthat delegates to the givenStatefulIntHash.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringalgorithm()Returns the canonical name of this hash algorithm.StatelessLongHashasStateless()Returns an instance of stateless version of this hash function.StatefulHashcreateNew()Returns a new instance of this stateful hash function reset to the initial state.bytegetByte()Returns the first byte of the output of this hash function.byte[]getBytes()Returns a new byte array containing the output of this hash function.intgetBytes(byte[] output, int index, int maxLength)Writes the output of this hash function into the given byte array at the given offset.intgetInt()Returns the first four bytes of the output of this hash function as a little-endianint.longgetLong()Returns the first eight bytes of the output of this hash function as a little-endianlong.shortgetShort()Returns the first two bytes of the output of this hash function as a little-endianshort.intlength()Returns the length in bytes of the output of this hash function.voidreset()Resets this hash function to its initial state.booleansupportsIncremental()Returns whether this hash function supports incremental hashing.booleansupportsUnsafe()Returns whether this hash function supports unsafe access to arbitrary memory addresses using methods such asStatefulHash.update(long, long),StatelessIntHash.calculate(long, long), orIncrementalIntHash.resume(int, long, long).voidupdate(byte[] input)Updates the state of this hash function with the entire given input array.voidupdate(byte[] input, int index, int length)Updates the state of this hash function with the given range of the given input array.voidupdate(long address, long length)Updates the state of this hash function with memory with the given address and length.voidupdate(java.nio.ByteBuffer input)Updates the state of this hash function with the remaining contents of the given input buffer.
-
-
-
Constructor Detail
-
IntStatefulLongHash
public IntStatefulLongHash(StatefulIntHash intHash)
Constructs a newIntStatefulLongHashthat delegates to the givenStatefulIntHash.- Parameters:
intHash- the underlying int-width hash
-
-
Method Detail
-
asStateless
public StatelessLongHash asStateless()
Description copied from interface:StatefulLongHashReturns an instance of stateless version of this hash function.- Specified by:
asStatelessin interfaceStatefulLongHash- Returns:
- the stateless version of this hash function
-
algorithm
public java.lang.String algorithm()
Description copied from interface:HashReturns the canonical name of this hash algorithm.
-
length
public int length()
Description copied from interface:HashReturns the length in bytes of the output of this hash function.
-
createNew
public StatefulHash createNew()
Description copied from interface:StatefulHashReturns a new instance of this stateful hash function reset to the initial state.- Specified by:
createNewin interfaceStatefulHash- Returns:
- a new instance of this hash in the initial state
-
supportsUnsafe
public boolean supportsUnsafe()
Description copied from interface:HashReturns whether this hash function supports unsafe access to arbitrary memory addresses using methods such asStatefulHash.update(long, long),StatelessIntHash.calculate(long, long), orIncrementalIntHash.resume(int, long, long). Such functions are generally implemented in native code.- Specified by:
supportsUnsafein interfaceHash- Returns:
- true if unsafe access is supported, false if not
-
supportsIncremental
public boolean supportsIncremental()
Description copied from interface:StatefulHashReturns whether this hash function supports incremental hashing. Incremental hashing allows calling theStatefulHash.update(byte[])methods to continue hashing using accumulated state after calling any of the output methods (such asStatefulHash.getBytes()). Non-incremental hash functions require callingStatefulHash.reset()to reinitialize the state between calling an output method and an update method.- Specified by:
supportsIncrementalin interfaceStatefulHash- Returns:
- true if incremental hashing is supported, false if not
-
reset
public void reset()
Description copied from interface:StatefulHashResets this hash function to its initial state. Resetting the state is required for non-incremental hash functions after any output methods have been called.- Specified by:
resetin interfaceStatefulHash
-
update
public void update(byte[] input)
Description copied from interface:StatefulHashUpdates the state of this hash function with the entire given input array.- Specified by:
updatein interfaceStatefulHash- Parameters:
input- the input array
-
update
public void update(byte[] input, int index, int length)Description copied from interface:StatefulHashUpdates the state of this hash function with the given range of the given input array.- Specified by:
updatein interfaceStatefulHash- Parameters:
input- the input arrayindex- the starting index of the first input bytelength- the length of the input range
-
update
public void update(java.nio.ByteBuffer input)
Description copied from interface:StatefulHashUpdates the state of this hash function with the remaining contents of the given input buffer. This method leaves the buffer position at the limit.- Specified by:
updatein interfaceStatefulHash- Parameters:
input- the input buffer
-
update
public void update(long address, long length)Description copied from interface:StatefulHashUpdates the state of this hash function with memory with the given address and length. The arguments are generally not checked in any way and will likely lead to a VM crash or undefined results if invalid.- Specified by:
updatein interfaceStatefulHash- Parameters:
address- the base address of the inputlength- the length of the input- See Also:
Hash.supportsUnsafe()
-
getBytes
public byte[] getBytes()
Description copied from interface:StatefulHashReturns a new byte array containing the output of this hash function. The caller may freely modify the contents of the array.- Specified by:
getBytesin interfaceStatefulHash- Returns:
- a new byte array containing the hash output
-
getBytes
public int getBytes(byte[] output, int index, int maxLength)Description copied from interface:StatefulHashWrites the output of this hash function into the given byte array at the given offset.- Specified by:
getBytesin interfaceStatefulHash- Parameters:
output- the destination array for the outputindex- the starting index of the first output bytemaxLength- the maximum number of bytes to write- Returns:
- the number of bytes written
-
getByte
public byte getByte()
Description copied from interface:StatefulHashReturns the first byte of the output of this hash function.- Specified by:
getBytein interfaceStatefulHash- Returns:
- the first output byte
-
getShort
public short getShort()
Description copied from interface:StatefulHashReturns the first two bytes of the output of this hash function as a little-endianshort. If the output is less than two bytes, the remaining bytes are set to 0.- Specified by:
getShortin interfaceStatefulHash- Returns:
- the first two output bytes as a short
-
getInt
public int getInt()
Description copied from interface:StatefulHashReturns the first four bytes of the output of this hash function as a little-endianint. If the output is less than four bytes, the remaining bytes are set to 0.- Specified by:
getIntin interfaceStatefulHash- Returns:
- the first four output bytes as an int
-
getLong
public long getLong()
Description copied from interface:StatefulHashReturns the first eight bytes of the output of this hash function as a little-endianlong. If the output is less than eight bytes, the remaining bytes are set to 0.- Specified by:
getLongin interfaceStatefulHash- Returns:
- the first eight output bytes as a long
-
-