Module notzed.dez
Package au.notzed.dez

Class CyclicHash


  • public class CyclicHash
    extends java.lang.Object
    Cyclic polynomial rolling hash.

    This implements a rolling hash of a fixed length.

    Input bytes are hashed using a random table. The randomness affects the quality of the hash.

    • Constructor Summary

      Constructors 
      Constructor Description
      CyclicHash​(int length)
      Creates a cyclic hash.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int init​(byte[] data, int off)
      Initialises the hash.
      int update​(byte leave, byte enter)
      Updates the hash incrementally.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CyclicHash

        public CyclicHash​(int length)
        Creates a cyclic hash.
        Parameters:
        length - The block length for the hash.
    • Method Detail

      • init

        public int init​(byte[] data,
                        int off)
        Initialises the hash.

        This will hash one block of data at the given location.

        Parameters:
        data - Data buffer.
        off - Offset into data.
        Returns:
        The hash code of this block.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - If the buffer is too short.
      • update

        public int update​(byte leave,
                          byte enter)
        Updates the hash incrementally.

        Advance the hash by one location.

        Parameters:
        leave - the byte leaving. Must match the oldest byte included in the hash value.
        enter - the byte entering.
        Returns:
        The hash code for the last block-size bytes.