You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/12/22 02:53:30 UTC

(commons-compress) branch master updated (87a96f1c7 -> 559215213)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


    from 87a96f1c7 Javadoc spelling
     new a2dd1ef09 Reimplement for reuse
     new 559215213 Javadoc

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/compress/compressors/lz4/XXHash32.java | 137 +--------------------
 .../commons/compress/utils/BoundedInputStream.java |   4 +-
 2 files changed, 6 insertions(+), 135 deletions(-)


(commons-compress) 01/02: Reimplement for reuse

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit a2dd1ef097e80df78d86766106b9f1d829a49515
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 21 21:49:04 2023 -0500

    Reimplement for reuse
---
 .../commons/compress/compressors/lz4/XXHash32.java | 137 +--------------------
 1 file changed, 3 insertions(+), 134 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/XXHash32.java b/src/main/java/org/apache/commons/compress/compressors/lz4/XXHash32.java
index c1e266281..8846e6a36 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz4/XXHash32.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz4/XXHash32.java
@@ -18,11 +18,6 @@
  */
 package org.apache.commons.compress.compressors.lz4;
 
-import static java.lang.Integer.rotateLeft;
-import static org.apache.commons.compress.utils.ByteUtils.fromLittleEndian;
-
-import java.util.zip.Checksum;
-
 /**
  * Implementation of the xxhash32 hash algorithm.
  *
@@ -32,37 +27,13 @@ import java.util.zip.Checksum;
  * @deprecated Use {@link org.apache.commons.codec.digest.XXHash32}.
  */
 @Deprecated
-public class XXHash32 implements Checksum {
-
-    private static final int BUF_SIZE = 16;
-    private static final int ROTATE_BITS = 13;
-
-    private static final int PRIME1 = (int) 2654435761L;
-    private static final int PRIME2 = (int) 2246822519L;
-    private static final int PRIME3 = (int) 3266489917L;
-    private static final int PRIME4 = 668265263;
-    private static final int PRIME5 = 374761393;
-
-    private static int getInt(final byte[] buffer, final int idx) {
-        return (int) (fromLittleEndian(buffer, idx, 4) & 0xffffffffL);
-    }
-
-    private final byte[] oneByte = new byte[1];
-    private final int[] state = new int[4];
-    // Note: the code used to use ByteBuffer but the manual method is 50% faster
-    // See: https://gitbox.apache.org/repos/asf/commons-compress/diff/2f56fb5c
-    private final byte[] buffer = new byte[BUF_SIZE];
-
-    private final int seed;
-    private int totalLen;
-
-    private int pos;
+public class XXHash32 extends org.apache.commons.codec.digest.XXHash32 {
 
     /**
      * Creates an XXHash32 instance with a seed of 0.
      */
     public XXHash32() {
-        this(0);
+        super(0);
     }
 
     /**
@@ -71,108 +42,6 @@ public class XXHash32 implements Checksum {
      * @param seed the seed to use
      */
     public XXHash32(final int seed) {
-        this.seed = seed;
-        initializeState();
-    }
-
-    @Override
-    public long getValue() {
-        int hash;
-        if (totalLen > BUF_SIZE) {
-            hash = rotateLeft(state[0], 1) + rotateLeft(state[1], 7) + rotateLeft(state[2], 12) + rotateLeft(state[3], 18);
-        } else {
-            hash = state[2] + PRIME5;
-        }
-        hash += totalLen;
-
-        int idx = 0;
-        final int limit = pos - 4;
-        for (; idx <= limit; idx += 4) {
-            hash = rotateLeft(hash + getInt(buffer, idx) * PRIME3, 17) * PRIME4;
-        }
-        while (idx < pos) {
-            hash = rotateLeft(hash + (buffer[idx++] & 0xff) * PRIME5, 11) * PRIME1;
-        }
-
-        hash ^= hash >>> 15;
-        hash *= PRIME2;
-        hash ^= hash >>> 13;
-        hash *= PRIME3;
-        hash ^= hash >>> 16;
-        return hash & 0xffffffffL;
-    }
-
-    private void initializeState() {
-        state[0] = seed + PRIME1 + PRIME2;
-        state[1] = seed + PRIME2;
-        state[2] = seed;
-        state[3] = seed - PRIME1;
-    }
-
-    private void process(final byte[] b, final int offset) {
-        // local shadows for performance
-        int s0 = state[0];
-        int s1 = state[1];
-        int s2 = state[2];
-        int s3 = state[3];
-
-        s0 = rotateLeft(s0 + getInt(b, offset) * PRIME2, ROTATE_BITS) * PRIME1;
-        s1 = rotateLeft(s1 + getInt(b, offset + 4) * PRIME2, ROTATE_BITS) * PRIME1;
-        s2 = rotateLeft(s2 + getInt(b, offset + 8) * PRIME2, ROTATE_BITS) * PRIME1;
-        s3 = rotateLeft(s3 + getInt(b, offset + 12) * PRIME2, ROTATE_BITS) * PRIME1;
-
-        state[0] = s0;
-        state[1] = s1;
-        state[2] = s2;
-        state[3] = s3;
-
-        pos = 0;
-    }
-
-    @Override
-    public void reset() {
-        initializeState();
-        totalLen = 0;
-        pos = 0;
-    }
-
-    @Override
-    public void update(final byte[] b, int off, final int len) {
-        if (len <= 0) {
-            return;
-        }
-        totalLen += len;
-
-        final int end = off + len;
-
-        if (pos + len < BUF_SIZE) {
-            System.arraycopy(b, off, buffer, pos, len);
-            pos += len;
-            return;
-        }
-
-        if (pos > 0) {
-            final int size = BUF_SIZE - pos;
-            System.arraycopy(b, off, buffer, pos, size);
-            process(buffer, 0);
-            off += size;
-        }
-
-        final int limit = end - BUF_SIZE;
-        while (off <= limit) {
-            process(b, off);
-            off += BUF_SIZE;
-        }
-
-        if (off < end) {
-            pos = end - off;
-            System.arraycopy(b, off, buffer, 0, pos);
-        }
-    }
-
-    @Override
-    public void update(final int b) {
-        oneByte[0] = (byte) (b & 0xff);
-        update(oneByte, 0, 1);
+        super(seed);
     }
 }


(commons-compress) 02/02: Javadoc

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 5592152134d71163054f76fcc6dee95fdbde30f0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 21 21:49:32 2023 -0500

    Javadoc
---
 .../java/org/apache/commons/compress/utils/BoundedInputStream.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
index 0f1f30f2d..620e227fd 100644
--- a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
@@ -47,7 +47,9 @@ public class BoundedInputStream extends FilterInputStream {
     }
 
     /**
-     * @return bytes remaining to read
+     * Gets how many bytes remain to read.
+     *
+     * @return bytes how many bytes remain to read.
      * @since 1.21
      */
     public long getBytesRemaining() {