@@ -0,0 +1,2439 @@
+/*-%0A * Copyright (c) 2014 Mikolaj Izdebski%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.lbzip2.impl;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * @author Mikolaj Izdebski%0A */%0Aclass Encoder%0A%7B%0A    private final int%5B%5D cmap = new int%5B256%5D;%0A%0A    private final int%5B%5D order = new int%5B255%5D;%0A%0A    int EOB;%0A%0A    int do_mtf( int%5B%5D bwt, short%5B%5D mtfv, int%5B%5D mtffreq, boolean%5B%5D inuse, int nblock )%0A    %7B%0A        int i;%0A        int j;%0A        int k;%0A        int t;%0A        int c;%0A        int u;%0A        int bwt_off = 0;%0A        int mtfv_off = 0;%0A%0A        j = 0;%0A%0A        for ( i = 0; i %3C 256; i++ )%0A        %7B%0A            k = inuse%5Bi%5D ? 1 : 0;%0A%0A            cmap%5Bi%5D = j;%0A            j += k;%0A        %7D%0A%0A        EOB = j;%0A%0A        Arrays.fill( mtffreq, 0 );%0A%0A        k = 0;%0A        u = 0;%0A        for ( i = 0; i %3C 255; i++ )%0A            order%5Bi%5D = i + 1;%0A%0A        for ( i = 0; i %3C nblock; i++ )%0A        %7B%0A            if ( ( c = cmap%5Bbwt%5Bbwt_off++%5D%5D ) == u )%0A            %7B%0A                k++;%0A                continue;%0A            %7D%0A%0A            while ( k != 0 )%0A            %7B%0A                mtffreq%5Bmtfv%5Bmtfv_off++%5D = (short) ( --k & 1 )%5D++;%0A                k %3E%3E= 1;%0A            %7D%0A%0A            int p = 0;%0A            t = order%5B0%5D;%0A            order%5B0%5D = u;%0A            for ( ;; )%0A            %7B%0A                if ( c == t )%0A                %7B%0A                    u = t;%0A                    break;%0A                %7D%0A                u = order%5B++p%5D;%0A                order%5Bp%5D = t;%0A                if ( c == u )%0A                    break;%0A                t = order%5B++p%5D;%0A                order%5Bp%5D = u;%0A            %7D%0A            t = p + 2;%0A            mtfv%5Bmtfv_off++%5D = (short) t;%0A            mtffreq%5Bt%5D++;%0A        %7D%0A%0A        while ( k != 0 )%0A        %7B%0A            mtffreq%5Bmtfv%5Bmtfv_off++%5D = (short) ( --k & 1 )%5D++;%0A            k %3E%3E= 1;%0A        %7D%0A%0A        mtfv%5Bmtfv_off++%5D = (short) EOB;%0A        mtffreq%5BEOB%5D++;%0A%0A        return mtfv_off;%0A    %7D%0A%7D%0A

Implement MTF coder