size -> length
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/eba864c6 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/eba864c6 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/eba864c6 Branch: refs/heads/master Commit: eba864c6f21243374bcf5b7300ad65c33b94f64e Parents: aa81e37 Author: Stefan Bodewig <[email protected]> Authored: Sat Jan 7 18:10:23 2017 +0100 Committer: Stefan Bodewig <[email protected]> Committed: Sat Jan 7 18:10:23 2017 +0100 ---------------------------------------------------------------------- .../compressors/lz77support/LZ77Compressor.java | 24 ++++---- .../compressors/lz77support/Parameters.java | 58 ++++++++++---------- .../compressors/lz77support/ParametersTest.java | 38 ++++++------- 3 files changed, 60 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/eba864c6/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java index 2a6fe3d..7e10715 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java @@ -60,19 +60,19 @@ package org.apache.commons.compress.compressors.lz77support; * buffer of twice of <code>windowSize</code> - real world values are * in the area of 32k.</dd> * - * <dt><code>minMatchSize</code></dt> - * <dd>Minimal size of a match found. A true minimum of 3 is - * hard-coded inside of this implemention but bigger sizes can be + * <dt><code>minMatchLength</code></dt> + * <dd>Minimal length of a match found. A true minimum of 3 is + * hard-coded inside of this implemention but bigger lengths can be * configured.</dd> * - * <dt><code>maxMatchSize</code></dt> - * <dd>Maximal size of a match found.</dd> + * <dt><code>maxMatchLength</code></dt> + * <dd>Maximal length of a match found.</dd> * * <dt><code>maxOffset</code></dt> * <dd>Maximal offset of a back-reference.</dd> * - * <dt><code>maxLiteralSize</code></dt> - * <dd>Maximal size of a literal block.</dd> + * <dt><code>maxLiteralLength</code></dt> + * <dd>Maximal length of a literal block.</dd> * </dl> * * @see "https://tools.ietf.org/html/rfc1951#section-4" @@ -308,7 +308,7 @@ public class LZ77Compressor { } System.arraycopy(data, off, window, currentPosition + lookahead, len); lookahead += len; - if (!initialized && lookahead >= params.getMinMatchSize()) { + if (!initialized && lookahead >= params.getMinMatchLength()) { initialize(); } if (initialized) { @@ -340,7 +340,7 @@ public class LZ77Compressor { } private void compress() { - final int minMatch = params.getMinMatchSize(); + final int minMatch = params.getMinMatchLength(); while (lookahead >= minMatch) { catchUpMissedInserts(); @@ -365,7 +365,7 @@ public class LZ77Compressor { // no match, append to current or start a new literal lookahead--; currentPosition++; - if (currentPosition - blockStart >= params.getMaxLiteralSize()) { + if (currentPosition - blockStart >= params.getMaxLiteralLength()) { flushLiteralBlock(); blockStart = currentPosition; } @@ -422,9 +422,9 @@ public class LZ77Compressor { * longest match as a side effect.</p> */ private int longestMatch(int matchHead) { - final int minLength = params.getMinMatchSize(); + final int minLength = params.getMinMatchLength(); int longestMatchLength = minLength - 1; - final int maxPossibleLength = Math.min(params.getMaxMatchSize(), lookahead); + final int maxPossibleLength = Math.min(params.getMaxMatchLength(), lookahead); final int minIndex = Math.max(0, currentPosition - params.getMaxOffset()); while (matchHead >= minIndex) { int currentLength = 0; http://git-wip-us.apache.org/repos/asf/commons-compress/blob/eba864c6/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java index 6f2b2cb..1149302 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/Parameters.java @@ -22,21 +22,21 @@ package org.apache.commons.compress.compressors.lz77support; * Parameters of the {@link LZ77Compressor compressor}. */ public final class Parameters { - public static final int TRUE_MIN_MATCH_SIZE = LZ77Compressor.NUMBER_OF_BYTES_IN_HASH; - private final int windowSize, minMatchSize, maxMatchSize, maxOffset, maxLiteralSize; + public static final int TRUE_MIN_MATCH_LENGTH = LZ77Compressor.NUMBER_OF_BYTES_IN_HASH; + private final int windowSize, minMatchLength, maxMatchLength, maxOffset, maxLiteralLength; /** * Initializes the compressor's parameters with a - * <code>minMatchSize</code> of 3 and <code>max*Size</code> + * <code>minMatchLength</code> of 3 and <code>max*Length</code> * equal to <code>windowSize</code>. * * @param windowSize the size of the sliding window - this * determines the maximum offset a back-reference can take. * @throws IllegalArgumentException if <code>windowSize</code> - * is smaller than <code>minMatchSize</code>. + * is smaller than <code>minMatchLength</code>. */ public Parameters(int windowSize) { - this(windowSize, TRUE_MIN_MATCH_SIZE, windowSize, windowSize, windowSize); + this(windowSize, TRUE_MIN_MATCH_LENGTH, windowSize, windowSize, windowSize); } /** @@ -45,25 +45,25 @@ public final class Parameters { * @param windowSize the size of the sliding window, must be a * power of two - this determines the maximum offset a * back-reference can take. - * @param minMatchSize the minimal size of a match found. A + * @param minMatchLength the minimal length of a match found. A * true minimum of 3 is hard-coded inside of this implemention - * but bigger sizes can be configured. - * @param maxMatchSize maximal site of a match found. A value - * smaller than <code>minMatchSize</code> is interpreted as + * but bigger lengths can be configured. + * @param maxMatchLength maximal site of a match found. A value + * smaller than <code>minMatchLength</code> is interpreted as * infinite (actually {@link Integer.MAX_VALUE}). * @param maxOffset maximal offset of a back-reference. A * non-positive value is interpreted as <code>windowSize</code>. - * @param maxLiteralSize maximal size of a literal block. Negative + * @param maxLiteralLength maximal length of a literal block. Negative * numbers and 0 as well as values bigger than <code>2 * * windowSize</code> are interpreted as <code>windowSize</code>. * @throws IllegalArgumentException if <code>windowSize</code> is - * smaller than <code>minMatchSize</code> or not a power of two. + * smaller than <code>minMatchLength</code> or not a power of two. */ - public Parameters(int windowSize, int minMatchSize, int maxMatchSize, - int maxOffset, int maxLiteralSize) { - this.minMatchSize = Math.max(TRUE_MIN_MATCH_SIZE, minMatchSize); - if (windowSize < this.minMatchSize) { - throw new IllegalArgumentException("windowSize must be at least as big as minMatchSize"); + public Parameters(int windowSize, int minMatchLength, int maxMatchLength, + int maxOffset, int maxLiteralLength) { + this.minMatchLength = Math.max(TRUE_MIN_MATCH_LENGTH, minMatchLength); + if (windowSize < this.minMatchLength) { + throw new IllegalArgumentException("windowSize must be at least as big as minMatchLength"); } if (!isPowerOfTwo(windowSize)) { throw new IllegalArgumentException("windowSize must be a power of two"); @@ -71,10 +71,10 @@ public final class Parameters { this.windowSize = windowSize; this.maxOffset = maxOffset < 1 ? this.windowSize : Math.min(maxOffset, this.windowSize); - this.maxMatchSize = maxMatchSize < this.minMatchSize ? Integer.MAX_VALUE - : maxMatchSize; - this.maxLiteralSize = maxLiteralSize < 1 || maxLiteralSize > 2 * windowSize - ? windowSize : maxLiteralSize; + this.maxMatchLength = maxMatchLength < this.minMatchLength ? Integer.MAX_VALUE + : maxMatchLength; + this.maxLiteralLength = maxLiteralLength < 1 || maxLiteralLength > 2 * windowSize + ? windowSize : maxLiteralLength; } /** @@ -85,16 +85,16 @@ public final class Parameters { return windowSize; } /** - * Gets the minimal size of a match found. + * Gets the minimal length of a match found. */ - public int getMinMatchSize() { - return minMatchSize; + public int getMinMatchLength() { + return minMatchLength; } /** - * Gets the maximal size of a match found. + * Gets the maximal length of a match found. */ - public int getMaxMatchSize() { - return maxMatchSize; + public int getMaxMatchLength() { + return maxMatchLength; } /** * Gets the maximal offset of a match found. @@ -103,10 +103,10 @@ public final class Parameters { return maxOffset; } /** - * Gets the maximal size of a literal block. + * Gets the maximal length of a literal block. */ - public int getMaxLiteralSize() { - return maxLiteralSize; + public int getMaxLiteralLength() { + return maxLiteralLength; } private static final boolean isPowerOfTwo(int x) { http://git-wip-us.apache.org/repos/asf/commons-compress/blob/eba864c6/src/test/java/org/apache/commons/compress/compressors/lz77support/ParametersTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/compress/compressors/lz77support/ParametersTest.java b/src/test/java/org/apache/commons/compress/compressors/lz77support/ParametersTest.java index 43317cc..b26cd85 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz77support/ParametersTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz77support/ParametersTest.java @@ -28,28 +28,28 @@ public class ParametersTest { public void defaultConstructor() { Parameters p = new Parameters(128); assertEquals(128, p.getWindowSize()); - assertEquals(3, p.getMinMatchSize()); - assertEquals(128, p.getMaxMatchSize()); + assertEquals(3, p.getMinMatchLength()); + assertEquals(128, p.getMaxMatchLength()); assertEquals(128, p.getMaxOffset()); - assertEquals(128, p.getMaxLiteralSize()); + assertEquals(128, p.getMaxLiteralLength()); } @Test - public void minMatchSizeIsAtLeastThree() { + public void minMatchLengthIsAtLeastThree() { Parameters p = new Parameters(128, 2, 3, 4, 5); - assertEquals(3, p.getMinMatchSize()); + assertEquals(3, p.getMinMatchLength()); } @Test - public void maxMatchSizeIsInfiniteWhenSmallerThanMinMatchSize() { + public void maxMatchLengthIsInfiniteWhenSmallerThanMinMatchLength() { Parameters p = new Parameters(128, 2, 2, 4, 5); - assertEquals(Integer.MAX_VALUE, p.getMaxMatchSize()); + assertEquals(Integer.MAX_VALUE, p.getMaxMatchLength()); } @Test - public void maxMatchSizeIsMinMatchSizeIfBothAreEqual() { + public void maxMatchLengthIsMinMatchLengthIfBothAreEqual() { Parameters p = new Parameters(128, 2, 3, 4, 5); - assertEquals(3, p.getMaxMatchSize()); + assertEquals(3, p.getMaxMatchLength()); } @Test @@ -71,35 +71,35 @@ public class ParametersTest { } @Test - public void maxLiteralSizeIsWindowSizeIfSetTo0() { + public void maxLiteralLengthIsWindowSizeIfSetTo0() { Parameters p = new Parameters(128, 2, 3, 4, 0); - assertEquals(128, p.getMaxLiteralSize()); + assertEquals(128, p.getMaxLiteralLength()); } @Test - public void maxLiteralSizeIsWindowSizeIfSetToANegativeValue() { + public void maxLiteralLengthIsWindowSizeIfSetToANegativeValue() { Parameters p = new Parameters(128, 2, 3, 0, -1); - assertEquals(128, p.getMaxLiteralSize()); + assertEquals(128, p.getMaxLiteralLength()); } @Test - public void maxLiteralSizeIsWindowSizeIfSetToAValueTooBigToHoldInSlidingWindow() { + public void maxLiteralLengthIsWindowSizeIfSetToAValueTooBigToHoldInSlidingWindow() { Parameters p = new Parameters(128, 2, 3, 0, 259); - assertEquals(128, p.getMaxLiteralSize()); + assertEquals(128, p.getMaxLiteralLength()); } @Test public void allParametersUsuallyTakeTheirSpecifiedValues() { Parameters p = new Parameters(256, 4, 5, 6, 7); assertEquals(256, p.getWindowSize()); - assertEquals(4, p.getMinMatchSize()); - assertEquals(5, p.getMaxMatchSize()); + assertEquals(4, p.getMinMatchLength()); + assertEquals(5, p.getMaxMatchLength()); assertEquals(6, p.getMaxOffset()); - assertEquals(7, p.getMaxLiteralSize()); + assertEquals(7, p.getMaxLiteralLength()); } @Test(expected = IllegalArgumentException.class) - public void windowSizeMustNotBeSmallerThanMinMatchSize() { + public void windowSizeMustNotBeSmallerThanMinMatchLength() { new Parameters(128, 200, 300, 400, 500); }
