📄 modelppm.java.svn-base
字号:
public void setInitEsc(int initEsc)
{
this.initEsc = initEsc;
}
public void setRunLength(int runLength)
{
this.runLength = runLength;
}
public int getRunLength()
{
return runLength;
}
public byte getPrevSuccess()
{
return prevSuccess;
}
public byte getHiBitsFlag()
{
return hiBitsFlag;
}
public void setHiBitsFlag(byte hiBitsFlag)
{
this.hiBitsFlag = hiBitsFlag;
}
public short[][] getBinSumm()
{
return binSumm;
}
public RangeCoder getCoder()
{
return coder;
}
public byte[] getHB2Flag()
{
return HB2Flag;
}
public byte[] getNS2BSIndx()
{
return NS2BSIndx;
}
public byte[] getNS2Indx()
{
return NS2Indx;
}
public State getFoundState()
{
return foundState;
}
public byte[] getHeap()
{
return subAlloc.getHeap();
}
public int getOrderFall()
{
return orderFall;
}
private int /* ppmcontext ptr */createSuccessors(boolean Skip, State p1 /*
* state
* ptr
*/)
{
State UpState = new State(null);
State tempState = new State(getHeap());
// PPM_CONTEXT* pc=MinContext, * UpBranch=FoundState->Successor;
PPMContext pc = new PPMContext(getHeap());
pc.setAddress(minContext.getAddress());
PPMContext upBranch = new PPMContext(getHeap());
upBranch.setAddress(foundState.getSuccessor());
// STATE * p, * ps[MAX_O], ** pps=ps;
State p = new State(getHeap());
int[] ps = new int[MAX_O];
int pps = 0;
boolean noLoop = false;
if (!Skip) {
ps[pps++] = foundState.getAddress();// *pps++ = FoundState;
if (pc.getSuffix() == 0) {
noLoop = true;
}
}
if (!noLoop) {
boolean loopEntry = false;
if (p1.getAddress() != 0) {
p.setAddress(p1.getAddress());
pc.setAddress(pc.getSuffix());// =pc->Suffix;
loopEntry = true;
}
do {
if (!loopEntry) {
pc.setAddress(pc.getSuffix());// pc=pc->Suffix;
if (pc.getNumStats() != 1) {
p.setAddress(pc.getFreqData().getStats());// p=pc->U.Stats
if (p.getSymbol() != foundState.getSymbol()) {
do {
p.incAddress();
} while (p.getSymbol() != foundState.getSymbol());
}
} else {
p.setAddress(pc.getOneState().getAddress());// p=&(pc->OneState);
}
}// LOOP_ENTRY:
loopEntry = false;
if (p.getSuccessor() != upBranch.getAddress()) {
pc.setAddress(p.getSuccessor());// =p->Successor;
break;
}
ps[pps++] = p.getAddress();
} while (pc.getSuffix() != 0);
} // NO_LOOP:
if (pps == 0) {
return pc.getAddress();
}
UpState.setSymbol(getHeap()[upBranch.getAddress()]);// UpState.Symbol=*(byte*)
// UpBranch;
// UpState.Successor=(PPM_CONTEXT*) (((byte*) UpBranch)+1);
UpState.setSuccessor(upBranch.getAddress() + 1); //TODO check if +1 necessary
if (pc.getNumStats() != 1) {
if (pc.getAddress() <= subAlloc.getPText()) {
return (0);
}
p.setAddress(pc.getFreqData().getStats());
if (p.getSymbol() != UpState.getSymbol()) {
do {
p.incAddress();
} while (p.getSymbol() != UpState.getSymbol());
}
int cf = ((int)p.getFreq()&0xff) - 1;
int s0 = pc.getFreqData().getSummFreq() - pc.getNumStats() - cf;
// UpState.Freq=1+((2*cf <= s0)?(5*cf > s0):((2*cf+3*s0-1)/(2*s0)));
UpState.setFreq((byte) (1 + ((2 * cf <= s0) ? (5 * cf > s0 ? 1 : 0)
: ((2 * cf + 3 * s0 - 1) / (2 * s0)))));
} else {
UpState.setFreq((byte) (pc.getOneState().getFreq()));// UpState.Freq=pc->OneState.Freq;
}
do {
// pc = pc->createChild(this,*--pps,UpState);
tempState.setAddress(ps[--pps]);
pc.setAddress(pc.createChild(this, tempState, UpState));
if (pc.getAddress() == 0) {
return 0;
}
} while (pps != 0);
return pc.getAddress();
}
private void updateModelRestart()
{
restartModelRare();
escCount = 0;
}
private void updateModel()
{
// STATE fs = *FoundState, *p = NULL;
State fs = new State(null);
fs.setValues(foundState);
State p = new State(getHeap());
State tempState = new State(getHeap());
PPMContext pc = new PPMContext(getHeap());
PPMContext Successor = new PPMContext(getHeap());
int ns1, ns, cf, sf, s0;
pc.setAddress(minContext.getSuffix());
if (fs.getFreq() < MAX_FREQ / 4 && pc.getAddress() != 0) {
if (pc.getNumStats() != 1) {
p.setAddress(pc.getFreqData().getStats());
if (p.getSymbol() != fs.getSymbol()) {
do {
p.incAddress();
} while (p.getSymbol() != fs.getSymbol());
tempState.setAddress(p.getAddress() - State.size);
if (p.getFreq() >= tempState.getFreq()) {
PPMContext.ppmdSwap(this, p, tempState);
p.decAddress();
}
}
if (p.getFreq() < MAX_FREQ - 9) {
p.setFreq((byte) (p.getFreq() + 2));
pc.getFreqData().setSummFreq(
(short) (pc.getFreqData().getSummFreq() + 2));
}
} else {
p.setAddress(pc.getOneState().getAddress());
p.setFreq((byte) (p.getFreq() + (((short)p.getFreq()&0xff) < 32 ? 1 : 0)));
}
}
if (orderFall == 0) {
foundState.setSuccessor(createSuccessors(true, p));
minContext.setAddress(foundState.getSuccessor());
maxContext.setAddress(foundState.getSuccessor());
if (minContext.getAddress() == 0) {
updateModelRestart();
return;
}
return;
}
subAlloc.getHeap()[subAlloc.getPText()] = fs.getSymbol();
subAlloc.incPText();
Successor.setAddress(subAlloc.getPText());
if (subAlloc.getPText() >= subAlloc.getFakeUnitsStart()) {
updateModelRestart();
return;
}
if (fs.getSuccessor() != 0) {
if (fs.getSuccessor() <= subAlloc.getPText()) {
fs.setSuccessor(createSuccessors(false, p));
if (fs.getSuccessor() == 0) {
updateModelRestart();
return;
}
}
if (--orderFall == 0) {
Successor.setAddress(fs.getSuccessor());
subAlloc
.setPText(subAlloc.getPText()
- (maxContext.getAddress() != minContext
.getAddress() ? 1 : 0));
}
} else {
foundState.setSuccessor(Successor.getAddress());
fs.setSuccessor(minContext);
}
ns = minContext.getNumStats();
s0 = minContext.getFreqData().getSummFreq() - (ns) - (fs.getFreq() - 1);
for (pc.setAddress(maxContext.getAddress()); pc.getAddress() != minContext
.getAddress(); pc.setAddress(pc.getSuffix())) {
if ((ns1 = pc.getNumStats()) != 1) {
if ((ns1 & 1) == 0) {
System.out.println(ns1);
pc.getFreqData().setStats(
subAlloc.expandUnits(pc.getFreqData().getStats(),
ns1 >>> 1));
if (pc.getFreqData().getStats() == 0) {
updateModelRestart();
return;
}
}
int sum = ((2 * ns1 < ns) ? 1 : 0)
+ 2
* ((4 * ((ns1 <= ns) ? 1 : 0)) & ((pc.getFreqData()
.getSummFreq() <= 8 * ns1) ? 1 : 0));
pc.getFreqData().setSummFreq(
(short) (pc.getFreqData().getSummFreq() + sum));
} else {
p.setAddress(subAlloc.allocUnits(1));
if (p.getAddress() == 0) {
updateModelRestart();
return;
}
p.setValues(pc.getOneState());
pc.getFreqData().setStats(p);
if (p.getFreq() < MAX_FREQ / 4 - 1) {
p.setFreq((byte) (p.getFreq() + p.getFreq()));
} else {
p.setFreq((byte) (MAX_FREQ - 4));
}
pc.getFreqData().setSummFreq(
(short) (p.getFreq() + initEsc + (ns > 3 ? 1 : 0)));
}
cf = 2 * fs.getFreq() * (pc.getFreqData().getSummFreq() + 6);
sf = s0 + pc.getFreqData().getSummFreq();
if (cf < 6 * sf) {
cf = 1 + (cf > sf ? 1 : 0) + (cf >= 4 * sf ? 1 : 0);
pc.getFreqData().setSummFreq(
(short) (pc.getFreqData().getSummFreq() + 3));
} else {
cf = 4 + (cf >= 9 * sf ? 1 : 0) + (cf >= 12 * sf ? 1 : 0)
+ (cf >= 15 * sf ? 1 : 0);
pc.getFreqData().setSummFreq(
(short) (pc.getFreqData().getSummFreq() + cf));
}
p.setAddress(pc.getFreqData().getStats() + ns1);
p.setSuccessor(Successor);
p.setSymbol(fs.getSymbol());
p.setFreq((byte) cf);
pc.setNumStats((short) ++ns1);
}
int successor = fs.getSuccessor();
maxContext.setAddress(successor);
minContext.setAddress(successor);
//TODO-----debug
int pos = minContext.getFreqData().getStats();
State a = new State(getHeap());
a.setAddress(pos);
pos+=State.size;
a.setAddress(pos);
//--dbg end
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -