internal void SetValues(StateRef state) { Symbol = state.Symbol; Freq = state.Freq; SetSuccessor(state.GetSuccessor()); }
private void UpdateModel() { //System.out.println("ModelPPM.updateModel()"); // STATE fs = *FoundState, *p = NULL; StateRef fs = _tempStateRef1; fs.Values = FoundState; State p = _tempState3.Initialize(Heap); State tempState = _tempState4.Initialize(Heap); PpmContext pc = _tempPpmContext3.Initialize(Heap); PpmContext successor = _tempPpmContext4.Initialize(Heap); int ns1, ns, cf, sf, s0; pc.Address = _minContext.GetSuffix(); if (fs.Freq < MAX_FREQ / 4 && pc.Address != 0) { if (pc.NumStats != 1) { p.Address = pc.FreqData.GetStats(); if (p.Symbol != fs.Symbol) { do { p.IncrementAddress(); }while (p.Symbol != fs.Symbol); tempState.Address = p.Address - State.SIZE; if (p.Freq >= tempState.Freq) { State.PpmdSwap(p, tempState); p.DecrementAddress(); } } if (p.Freq < MAX_FREQ - 9) { p.IncrementFreq(2); pc.FreqData.IncrementSummFreq(2); } } else { p.Address = pc.GetOneState().Address; if (p.Freq < 32) { p.IncrementFreq(1); } } } if (_orderFall == 0) { FoundState.SetSuccessor(CreateSuccessors(true, p)); _minContext.Address = FoundState.GetSuccessor(); _maxContext.Address = FoundState.GetSuccessor(); if (_minContext.Address == 0) { UpdateModelRestart(); return; } return; } SubAlloc.Heap[SubAlloc.PText] = (byte)fs.Symbol; SubAlloc.IncPText(); successor.Address = SubAlloc.PText; if (SubAlloc.PText >= SubAlloc.FakeUnitsStart) { UpdateModelRestart(); return; } // // Debug // subAlloc.dumpHeap(); if (fs.GetSuccessor() != 0) { if (fs.GetSuccessor() <= SubAlloc.PText) { fs.SetSuccessor(CreateSuccessors(false, p)); if (fs.GetSuccessor() == 0) { UpdateModelRestart(); return; } } if (--_orderFall == 0) { successor.Address = fs.GetSuccessor(); if (_maxContext.Address != _minContext.Address) { SubAlloc.DecPText(1); } } } else { FoundState.SetSuccessor(successor.Address); fs.SetSuccessor(_minContext); } // // Debug // subAlloc.dumpHeap(); ns = _minContext.NumStats; s0 = _minContext.FreqData.SummFreq - (ns) - (fs.Freq - 1); for (pc.Address = _maxContext.Address; pc.Address != _minContext.Address; pc.Address = pc.GetSuffix()) { if ((ns1 = pc.NumStats) != 1) { if ((ns1 & 1) == 0) { //System.out.println(ns1); pc.FreqData.SetStats(SubAlloc.ExpandUnits(pc.FreqData.GetStats(), Utility.URShift(ns1, 1))); if (pc.FreqData.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.FreqData.SummFreq <= 8 * ns1) ? 1 : 0)); pc.FreqData.IncrementSummFreq(sum); } else { p.Address = SubAlloc.AllocUnits(1); if (p.Address == 0) { UpdateModelRestart(); return; } p.SetValues(pc.GetOneState()); pc.FreqData.SetStats(p); if (p.Freq < MAX_FREQ / 4 - 1) { p.IncrementFreq(p.Freq); } else { p.Freq = MAX_FREQ - 4; } pc.FreqData.SummFreq = (p.Freq + _initEsc + (ns > 3 ? 1 : 0)); } cf = 2 * fs.Freq * (pc.FreqData.SummFreq + 6); sf = s0 + pc.FreqData.SummFreq; if (cf < 6 * sf) { cf = 1 + (cf > sf ? 1 : 0) + (cf >= 4 * sf ? 1 : 0); pc.FreqData.IncrementSummFreq(3); } else { cf = 4 + (cf >= 9 * sf ? 1 : 0) + (cf >= 12 * sf ? 1 : 0) + (cf >= 15 * sf ? 1 : 0); pc.FreqData.IncrementSummFreq(cf); } p.Address = pc.FreqData.GetStats() + ns1 * State.SIZE; p.SetSuccessor(successor); p.Symbol = fs.Symbol; p.Freq = cf; pc.NumStats = ++ns1; } int address = fs.GetSuccessor(); _maxContext.Address = address; _minContext.Address = address; //TODO-----debug // int pos = minContext.getFreqData().getStats(); // State a = new State(getHeap()); // a.Address=pos); // pos+=State.size; // a.Address=pos); //--dbg end }