Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82A82969F for ; Sun, 20 May 2012 14:01:51 +0000 (UTC) Received: (qmail 87326 invoked by uid 500); 20 May 2012 14:01:51 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 87257 invoked by uid 500); 20 May 2012 14:01:51 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 87250 invoked by uid 99); 20 May 2012 14:01:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 May 2012 14:01:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 May 2012 14:01:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E4E65238897A for ; Sun, 20 May 2012 14:01:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1340723 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java Date: Sun, 20 May 2012 14:01:26 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120520140126.E4E65238897A@eris.apache.org> Author: bodewig Date: Sun May 20 14:01:26 2012 New Revision: 1340723 URL: http://svn.apache.org/viewvc?rev=1340723&view=rev Log: just moving stuff around to closer match source code layout of libbzip2 1.0.6 Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java?rev=1340723&r1=1340722&r2=1340723&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java Sun May 20 14:01:26 2012 @@ -100,12 +100,6 @@ class BlockSort { * algorithm. */ - private static final int SETMASK = (1 << 21); - private static final int CLEARMASK = (~SETMASK); - private static final int SMALL_THRESH = 20; - private static final int DEPTH_THRESH = 10; - private static final int WORK_FACTOR = 30; - /* * LBZ2: If you are ever unlucky/improbable enough to get a stack * overflow whilst sorting, increase the following constant and @@ -114,15 +108,6 @@ class BlockSort { */ private static final int QSORT_STACK_SIZE = 1000; - /* - * LBZ2: Knuth's increments seem to work better than Incerpi-Sedgewick here. - * Possibly because the number of elems to sort is usually small, typically - * <= 20. - */ - private static final int[] INCS = { 1, 4, 13, 40, 121, 364, 1093, 3280, - 9841, 29524, 88573, 265720, 797161, - 2391484 }; - private boolean blockRandomised; /* @@ -154,14 +139,43 @@ class BlockSort { this.quadrant = data.sfmap; } + boolean blockSort(final BZip2CompressorOutputStream.Data data, final int last) { + this.workLimit = WORK_FACTOR * last; + this.workDone = 0; + this.blockRandomised = false; + this.firstAttempt = true; + mainSort(data, last); + + if (this.firstAttempt && (this.workDone > this.workLimit)) { + randomiseBlock(data, last); + this.workLimit = this.workDone = 0; + this.firstAttempt = false; + mainSort(data, last); + } + + final int[] fmap = data.fmap; + data.origPtr = -1; + for (int i = 0; i <= last; i++) { + if (fmap[i] == 0) { + data.origPtr = i; + break; + } + } + + // assert (data.origPtr != -1) : data.origPtr; + return blockRandomised; + } + /*---------------------------------------------*/ -/*-- - LBZ2: The following is an implementation of - an elegant 3-way quicksort for strings, - described in a paper "Fast Algorithms for - Sorting and Searching Strings", by Robert - Sedgewick and Jon L. Bentley. ---*/ + + /* + * LBZ2: Knuth's increments seem to work better than Incerpi-Sedgewick here. + * Possibly because the number of elems to sort is usually small, typically + * <= 20. + */ + private static final int[] INCS = { 1, 4, 13, 40, 121, 364, 1093, 3280, + 9841, 29524, 88573, 265720, 797161, + 2391484 }; /** * This is the most hammered method of this class. @@ -357,6 +371,14 @@ class BlockSort { return firstAttemptShadow && (workDoneShadow > workLimitShadow); } +/*-- + LBZ2: The following is an implementation of + an elegant 3-way quicksort for strings, + described in a paper "Fast Algorithms for + Sorting and Searching Strings", by Robert + Sedgewick and Jon L. Bentley. +--*/ + private static void vswap(int[] fmap, int p1, int p2, int n) { n += p1; while (p1 < n) { @@ -371,32 +393,9 @@ class BlockSort { : a); } - boolean blockSort(final BZip2CompressorOutputStream.Data data, final int last) { - this.workLimit = WORK_FACTOR * last; - this.workDone = 0; - this.blockRandomised = false; - this.firstAttempt = true; - mainSort(data, last); - - if (this.firstAttempt && (this.workDone > this.workLimit)) { - randomiseBlock(data, last); - this.workLimit = this.workDone = 0; - this.firstAttempt = false; - mainSort(data, last); - } - - final int[] fmap = data.fmap; - data.origPtr = -1; - for (int i = 0; i <= last; i++) { - if (fmap[i] == 0) { - data.origPtr = i; - break; - } - } - - // assert (data.origPtr != -1) : data.origPtr; - return blockRandomised; - } + private static final int SMALL_THRESH = 20; + private static final int DEPTH_THRESH = 10; + private static final int WORK_FACTOR = 30; /** * Method "mainQSort3", file "blocksort.c", BZip2 1.0.2 @@ -506,6 +505,9 @@ class BlockSort { } } + private static final int SETMASK = (1 << 21); + private static final int CLEARMASK = (~SETMASK); + private void mainSort(final BZip2CompressorOutputStream.Data dataShadow, final int lastShadow) { final int[] runningOrder = this.mainSort_runningOrder;