private void RestoreModel(PpmContext context, PpmContext minimumContext, PpmContext foundStateSuccessor) { PpmContext currentContext; Allocator.Text = Allocator.Heap; for (currentContext = maximumContext; currentContext != context; currentContext = currentContext.Suffix) { if (--currentContext.NumberStatistics == 0) { currentContext.Flags = (byte) ((currentContext.Flags & 0x10) + ((currentContext.Statistics.Symbol >= 0x40) ? 0x08 : 0x00)); PpmState state = currentContext.Statistics; Copy(currentContext.FirstState, state); Allocator.SpecialFreeUnits(state); currentContext.FirstStateFrequency = (byte)((currentContext.FirstStateFrequency + 11) >> 3); } else { Refresh((uint)((currentContext.NumberStatistics + 3) >> 1), false, currentContext); } } for (; currentContext != minimumContext; currentContext = currentContext.Suffix) { if (currentContext.NumberStatistics == 0) { currentContext.FirstStateFrequency -= (byte)(currentContext.FirstStateFrequency >> 1); } else if ((currentContext.SummaryFrequency += 4) > 128 + 4 * currentContext.NumberStatistics) { Refresh((uint)((currentContext.NumberStatistics + 2) >> 1), true, currentContext); } } if (method > ModelRestorationMethod.Freeze) { maximumContext = foundStateSuccessor; Allocator.GlueCount += (uint)(((Allocator.MemoryNodes[1].Stamp & 1) == 0) ? 1 : 0); } else if (method == ModelRestorationMethod.Freeze) { while (maximumContext.Suffix != PpmContext.Zero) { maximumContext = maximumContext.Suffix; } RemoveBinaryContexts(0, maximumContext); method = (ModelRestorationMethod)(method + 1); Allocator.GlueCount = 0; orderFall = modelOrder; } else if (method == ModelRestorationMethod.Restart || Allocator.GetMemoryUsed() < (Allocator.AllocatorSize >> 1)) { StartModel(modelOrder, method); escapeCount = 0; } else { while (maximumContext.Suffix != PpmContext.Zero) { maximumContext = maximumContext.Suffix; } do { CutOff(0, maximumContext); Allocator.ExpandText(); } while (Allocator.GetMemoryUsed() > 3 * (Allocator.AllocatorSize >> 2)); Allocator.GlueCount = 0; orderFall = modelOrder; } }