Пример #1
0
        private int createSuccessors(bool Skip, State p1)
        {
            //State upState = tempState1.Initialize(null);
            StateRef upState   = tempStateRef2;
            State    tempState = tempState1.Initialize(Heap);

            // PPM_CONTEXT* pc=MinContext, * UpBranch=FoundState->Successor;
            PPMContext pc = tempPPMContext1.Initialize(Heap);

            pc.Address = minContext.Address;
            PPMContext upBranch = tempPPMContext2.Initialize(Heap);

            upBranch.Address = foundState.GetSuccessor();

            // STATE * p, * ps[MAX_O], ** pps=ps;
            State p   = tempState2.Initialize(Heap);
            int   pps = 0;

            bool noLoop = false;

            if (!Skip)
            {
                ps[pps++] = foundState.Address; // *pps++ = FoundState;
                if (pc.getSuffix() == 0)
                {
                    noLoop = true;
                }
            }
            if (!noLoop)
            {
                bool loopEntry = false;
                if (p1.Address != 0)
                {
                    p.Address  = p1.Address;
                    pc.Address = pc.getSuffix(); // =pc->Suffix;
                    loopEntry  = true;
                }
                do
                {
                    if (!loopEntry)
                    {
                        pc.Address = pc.getSuffix(); // pc=pc->Suffix;
                        if (pc.NumStats != 1)
                        {
                            p.Address = pc.FreqData.GetStats(); // p=pc->U.Stats
                            if (p.Symbol != foundState.Symbol)
                            {
                                do
                                {
                                    p.IncrementAddress();
                                } while (p.Symbol != foundState.Symbol);
                            }
                        }
                        else
                        {
                            p.Address = pc.getOneState().Address; // p=&(pc->OneState);
                        }
                    } // LOOP_ENTRY:
                    loopEntry = false;
                    if (p.GetSuccessor() != upBranch.Address)
                    {
                        pc.Address = p.GetSuccessor(); // =p->Successor;
                        break;
                    }
                    ps[pps++] = p.Address;
                } while (pc.getSuffix() != 0);
            } // NO_LOOP:
            if (pps == 0)
            {
                return(pc.Address);
            }
            upState.Symbol = Heap[upBranch.Address]; // UpState.Symbol=*(byte*)
            // UpBranch;
            // UpState.Successor=(PPM_CONTEXT*) (((byte*) UpBranch)+1);
            upState.SetSuccessor(upBranch.Address + 1); //TODO check if +1 necessary
            if (pc.NumStats != 1)
            {
                if (pc.Address <= subAlloc.PText)
                {
                    return(0);
                }
                p.Address = pc.FreqData.GetStats();
                if (p.Symbol != upState.Symbol)
                {
                    do
                    {
                        p.IncrementAddress();
                    } while (p.Symbol != upState.Symbol);
                }
                int cf = p.Freq - 1;
                int s0 = pc.FreqData.SummFreq - pc.NumStats - cf;
                // UpState.Freq=1+((2*cf <= s0)?(5*cf > s0):((2*cf+3*s0-1)/(2*s0)));
                upState.Freq = 1 + ((2 * cf <= s0) ? (5 * cf > s0 ? 1 : 0) : ((2 * cf + 3 * s0 - 1) / (2 * s0)));
            }
            else
            {
                upState.Freq = pc.getOneState().Freq; // UpState.Freq=pc->OneState.Freq;
            }
            do
            {
                // pc = pc->createChild(this,*--pps,UpState);
                tempState.Address = ps[--pps];
                pc.Address        = pc.createChild(this, tempState, upState);
                if (pc.Address == 0)
                {
                    return(0);
                }
            } while (pps != 0);
            return(pc.Address);
        }
Пример #2
0
        private int createSuccessors(bool Skip, SharpCompress.Compressor.PPMd.H.State p1)
        {
            StateRef firstState = this.tempStateRef2;

            SharpCompress.Compressor.PPMd.H.State pStats = this.tempState1.Initialize(this.Heap);
            PPMContext context = this.tempPPMContext1.Initialize(this.Heap);

            context.Address = this.minContext.Address;
            PPMContext context2 = this.tempPPMContext2.Initialize(this.Heap);

            context2.Address = this.foundState.GetSuccessor();
            SharpCompress.Compressor.PPMd.H.State state2 = this.tempState2.Initialize(this.Heap);
            int  num  = 0;
            bool flag = false;

            if (!Skip)
            {
                this.ps[num++] = this.foundState.Address;
                if (context.getSuffix() == 0)
                {
                    flag = true;
                }
            }
            if (flag)
            {
                goto Label_01E0;
            }
            bool flag2 = false;

            if (p1.Address != 0)
            {
                state2.Address  = p1.Address;
                context.Address = context.getSuffix();
                flag2           = true;
            }
Label_00F2:
            if (!flag2)
            {
                context.Address = context.getSuffix();
                if (context.NumStats != 1)
                {
                    state2.Address = context.FreqData.GetStats();
                    if (state2.Symbol != this.foundState.Symbol)
                    {
                        do
                        {
                            state2.IncrementAddress();
                        }while (state2.Symbol != this.foundState.Symbol);
                    }
                }
                else
                {
                    state2.Address = context.getOneState().Address;
                }
            }
            flag2 = false;
            if (state2.GetSuccessor() != context2.Address)
            {
                context.Address = state2.GetSuccessor();
            }
            else
            {
                this.ps[num++] = state2.Address;
                if (context.getSuffix() != 0)
                {
                    goto Label_00F2;
                }
            }
Label_01E0:
            if (num != 0)
            {
                firstState.Symbol = this.Heap[context2.Address];
                firstState.SetSuccessor((int)(context2.Address + 1));
                if (context.NumStats != 1)
                {
                    if (context.Address <= this.subAlloc.PText)
                    {
                        return(0);
                    }
                    state2.Address = context.FreqData.GetStats();
                    if (state2.Symbol != firstState.Symbol)
                    {
                        do
                        {
                            state2.IncrementAddress();
                        }while (state2.Symbol != firstState.Symbol);
                    }
                    int num2 = state2.Freq - 1;
                    int num3 = (context.FreqData.SummFreq - context.NumStats) - num2;
                    firstState.Freq = 1 + (((2 * num2) <= num3) ? (((5 * num2) > num3) ? 1 : 0) : ((((2 * num2) + (3 * num3)) - 1) / (2 * num3)));
                }
                else
                {
                    firstState.Freq = context.getOneState().Freq;
                }
                do
                {
                    pStats.Address  = this.ps[--num];
                    context.Address = context.createChild(this, pStats, firstState);
                    if (context.Address == 0)
                    {
                        return(0);
                    }
                }while (num != 0);
            }
            return(context.Address);
        }