⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modelppm.java

📁 这是架包java-unrar-0.2.jar的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	public int getRunLength()
	{
		return runLength;
	}

    public void incRunLength(int dRunLength) {
        setRunLength(getRunLength() + dRunLength);
    }

	public int getPrevSuccess()
	{
		return prevSuccess;
	}

	public int getHiBitsFlag()
	{
		return hiBitsFlag;
	}

	public void setHiBitsFlag(int hiBitsFlag)
	{
		this.hiBitsFlag = hiBitsFlag&0xff;
	}

	public int[][] getBinSumm()
	{
		return binSumm;
	}

	public RangeCoder getCoder()
	{
		return coder;
	}

	public int[] getHB2Flag()
	{
		return HB2Flag;
	}

	public int[] getNS2BSIndx()
	{
		return NS2BSIndx;
	}

	public int[] 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 = tempState1.init(null);
		StateRef upState = tempStateRef2;
		State tempState = tempState1.init(getHeap());

		// PPM_CONTEXT* pc=MinContext, * UpBranch=FoundState->Successor;
		PPMContext pc = tempPPMContext1.init(getHeap());
		pc.setAddress(minContext.getAddress());
		PPMContext upBranch = tempPPMContext2.init(getHeap());
		upBranch.setAddress(foundState.getSuccessor());

		// STATE * p, * ps[MAX_O], ** pps=ps;
		State p = tempState2.init(getHeap());
		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 = p.getFreq() - 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(1 + ((2 * cf <= s0) ? (5 * cf > s0 ? 1 : 0) :
                    ((2 * cf + 3 * s0 - 1) / (2 * s0))));
		} else {
			upState.setFreq(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()
	{
        //System.out.println("ModelPPM.updateModel()");
		// STATE fs = *FoundState, *p = NULL;
		StateRef fs = tempStateRef1;
		fs.setValues(foundState);
		State p = tempState3.init(getHeap());
		State tempState = tempState4.init(getHeap());

		PPMContext pc = tempPPMContext3.init(getHeap());
		PPMContext successor = tempPPMContext4.init(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()) {
						State.ppmdSwap(p, tempState);
						p.decAddress();
					}
				}
				if (p.getFreq() < MAX_FREQ - 9) {
					p.incFreq(2);
					pc.getFreqData().incSummFreq(2);
				}
			} else {
				p.setAddress(pc.getOneState().getAddress());
                if (p.getFreq() < 32) {
                    p.incFreq(1);
                }
			}
		}
		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()] = (byte)fs.getSymbol();
		subAlloc.incPText();
		successor.setAddress(subAlloc.getPText());
		if (subAlloc.getPText() >= subAlloc.getFakeUnitsStart()) {
			updateModelRestart();
			return;
		}
//        // Debug
//        subAlloc.dumpHeap();
		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());
                if (maxContext.getAddress() != minContext.getAddress()) {
                    subAlloc.decPText(1);
                }
			}
		}
        else {
			foundState.setSuccessor(successor.getAddress());
			fs.setSuccessor(minContext);
		}
//        // Debug
//        subAlloc.dumpHeap();
		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;
					}
				}
                // bug fixed
//				int sum = ((2 * ns1 < ns) ? 1 : 0) +
//                        2 * ((4 * ((ns1 <= ns) ? 1 : 0)) & ((pc.getFreqData()
//								.getSummFreq() <= 8 * ns1) ? 1 : 0));
				int sum = ((2 * ns1 < ns) ? 1 : 0) + 2 * (
                        ((4 * ns1 <= ns) ? 1 : 0) &
                        ((pc.getFreqData().getSummFreq() <= 8 * ns1) ? 1 : 0)
                        );
				pc.getFreqData().incSummFreq(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.incFreq(p.getFreq());
				}
                else {
					p.setFreq(MAX_FREQ - 4);
				}
				pc.getFreqData().setSummFreq(
                        (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().incSummFreq(3);
			}
            else {
				cf = 4 + (cf >= 9 * sf ? 1 : 0) + (cf >= 12 * sf ? 1 : 0) +
                        (cf >= 15 * sf ? 1 : 0);
				pc.getFreqData().incSummFreq(cf);
			}
			p.setAddress(pc.getFreqData().getStats() + ns1*State.size);
			p.setSuccessor(successor);
			p.setSymbol(fs.getSymbol());
			p.setFreq(cf);
			pc.setNumStats(++ns1);
		}
		
		int address = fs.getSuccessor();
		maxContext.setAddress(address);
		minContext.setAddress(address);
		//TODO-----debug
//		int pos = minContext.getFreqData().getStats();
//		State a = new State(getHeap());
//		a.setAddress(pos);
//		pos+=State.size;
//		a.setAddress(pos);
		//--dbg end
		return;
	}

    // Debug
    public String toString() {
        StringBuilder buffer = new StringBuilder();
        buffer.append("ModelPPM[");
        buffer.append("\n  numMasked=");
        buffer.append(numMasked);
        buffer.append("\n  initEsc=");
        buffer.append(initEsc);
        buffer.append("\n  orderFall=");
        buffer.append(orderFall);
        buffer.append("\n  maxOrder=");
        buffer.append(maxOrder);
        buffer.append("\n  runLength=");
        buffer.append(runLength);
        buffer.append("\n  initRL=");
        buffer.append(initRL);
        buffer.append("\n  escCount=");
        buffer.append(escCount);
        buffer.append("\n  prevSuccess=");
        buffer.append(prevSuccess);
        buffer.append("\n  foundState=");
        buffer.append(foundState);
        buffer.append("\n  coder=");
        buffer.append(coder);
        buffer.append("\n  subAlloc=");
        buffer.append(subAlloc);
        buffer.append("\n]");
        return buffer.toString();
    }

    // Debug
//    public void dumpHeap() {
//        subAlloc.dumpHeap();
//    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -