Class Lz4XXHash32

  • All Implemented Interfaces:
    Checksum

    public final class Lz4XXHash32
    extends Object
    A special-purpose ByteBufChecksum implementation for use with Lz4FrameEncoder and Lz4FrameDecoder. StreamingXXHash32.asChecksum() has a particularly nasty implementation of Checksum.update(int) that allocates a single-element byte array for every invocation. In addition to that, it doesn't implement an overload that accepts a ByteBuffer as an argument. Combined, this means that we can't use ReflectiveByteBufChecksum at all, and can't use SlowByteBufChecksum because of its atrocious performance with direct byte buffers (allocating an array and making a JNI call for every byte checksummed might be considered sub-optimal by some). Block version of xxHash32 (XXHash32), however, does provide XXHash32.hash(ByteBuffer, int) method that is efficient and does exactly what we need, with a caveat that we can only invoke it once before having to reset. This, however, is fine for our purposes, given the way we use it in Lz4FrameEncoder and Lz4FrameDecoder: reset(), followed by one update(), followed by getValue().
    • Constructor Detail

      • Lz4XXHash32

        public Lz4XXHash32​(int seed)
    • Method Detail

      • update

        public void update​(int b)
      • update

        public void update​(byte[] b,
                           int off,
                           int len)
      • getValue

        public long getValue()
      • reset

        public void reset()