void* SubAllocator::ExpandUnits(void* OldPtr,int OldNU) { int i0=Units2Indx[OldNU-1], i1=Units2Indx[OldNU-1+1]; if (i0 == i1) return OldPtr; void* ptr=AllocUnits(OldNU+1); if ( ptr ) { memcpy(ptr,OldPtr,U2B(OldNU)); InsertNode(OldPtr,i0); } return ptr; }
static void _FASTCALL StartModelRare(int MaxOrder) { int i, k, m, Step; ::MaxOrder=OrderFall=MaxOrder; InitSubAllocator(); MinContext = MaxContext = (PPM_CONTEXT*) AllocContext(); MinContext->Suffix=NULL; MinContext->NumStats=255; FoundState = MinContext->Stats = (PPM_CONTEXT::STATE*) AllocUnits(256/2); for (i=MinContext->SummFreq=MinContext->EscFreq=0;i < 256;i++) { MinContext->Stats[i].Symbol=i; MinContext->Stats[i].Freq=0; MinContext->Stats[i].Successor=NULL; } for (i=0;i < UP_FREQ;i++) QTable[i]=i; for (m=i=UP_FREQ, k=Step=1;i < 260;i++) { QTable[i]=m; if ( !--k ) { k = ++Step; m++; } } }
static void RestartModel(PPMdModelVariantI *self) { InitSubAllocator(self->core.alloc); memset(self->core.CharMask,0,sizeof(self->core.CharMask)); self->core.PrevSuccess=0; self->core.OrderFall=self->MaxOrder; self->core.RunLength=self->core.InitRL=-((self->MaxOrder<12)?self->MaxOrder:12)-1; self->MaxContext=NewPPMdContext(&self->core); self->MaxContext->LastStateIndex=255; self->MaxContext->SummFreq=257; self->MaxContext->States=AllocUnits(self->core.alloc,256/2); PPMdState *maxstates=PPMdContextStates(self->MaxContext,&self->core); for(int i=0;i<256;i++) { maxstates[i].Symbol=i; maxstates[i].Freq=1; maxstates[i].Successor=0; } static const uint16_t InitBinEsc[8]={0x3cdd,0x1f3f,0x59bf,0x48f3,0x64a1,0x5abc,0x6632,0x6051}; int i=0; for(int m=0;m<25;m++) { while(self->QTable[i]==m) i++; for(int k=0;k<8;k++) self->BinSumm[m][k]=BIN_SCALE-InitBinEsc[k]/(i+1); for(int k=8;k<64;k+=8) memcpy(&self->BinSumm[m][k],&self->BinSumm[m][0],8*sizeof(uint16_t)); } i=0; for(int m=0;m<24;m++) { while(self->QTable[i+3]==m+3) i++; for(int k=0;k<32;k++) self->SEE2Cont[m][k]=MakeSEE2(2*i+5,7); } }
for(;currcontext!=mincontext;currcontext=PPMdContextSuffix(currcontext,&self->core)) { int currnum=currcontext->LastStateIndex+1; if(currnum!=1) { if((currnum&1)==0) { uint32_t states=ExpandUnits(self->core.alloc,currcontext->States,currnum>>1); if(!states) goto RESTART_MODEL; currcontext->States=states; } if(3*currnum-1<minnum) currcontext->SummFreq++; } else { PPMdState *states=OffsetToPointer(self->core.alloc,AllocUnits(self->core.alloc,1)); if(!states) goto RESTART_MODEL; states[0]=*(PPMdContextOneState(currcontext)); SetPPMdContextStatesPointer(currcontext,states,&self->core); if(states[0].Freq<MAX_FREQ/4-1) states[0].Freq*=2; else states[0].Freq=MAX_FREQ-4; currcontext->SummFreq=states[0].Freq+self->core.InitEsc+(minnum>3?1:0); } unsigned int cf=2*fs.Freq*(currcontext->SummFreq+6); unsigned int sf=s0+currcontext->SummFreq; unsigned int freq; if(cf<6*sf)
(fs.Successor=CreateSuccessors(FALSE,p)) == NULL) goto RESTART_MODEL; if ( !--OrderFall ) { Successor=fs.Successor; pText -= (MaxContext != MinContext); } } else { FoundState->Successor=Successor; fs.Successor=MinContext; } for (pc=MaxContext;pc != MinContext;pc=pc->Suffix) { if ((ns1=pc->NumStats) != 0) { if ((ns1 & 1) != 0) { pc->Stats=(PPM_CONTEXT::STATE*) ExpandUnits(pc->Stats,(ns1+1) >> 1); if ( !pc->Stats ) goto RESTART_MODEL; } } else { p=(PPM_CONTEXT::STATE*) AllocUnits(1); if ( !p ) goto RESTART_MODEL; *p=pc->oneState(); pc->Stats=p; pc->SummFreq=p->Freq; pc->Dummy=0; } p=pc->Stats+(++pc->NumStats); p->Successor=Successor; p->Symbol = fs.Symbol; p->Freq = p->Flag = 0; } MaxContext=MinContext=fs.Successor; return; RESTART_MODEL: printf("Out of memory!"); exit(-1); } inline void PPM_CONTEXT::encodeBinSymbol(int symbol) { STATE& rs=oneState();