private static void EncodeSymbol(PpmModel model, int[] history, int symbol, ArithmeticEncoder enc) { var order = history.Length; while (order >= 0) { var isBreak = false; var ctx = model.RootContext; for (var i = 0; i < order; i++) { ctx = ctx.Subcontexts[history[i]]; if (ctx == null) { order--; isBreak = true; break; } } if (isBreak) { continue; } if (symbol != EscapeSymbol && ctx.Frequencies.Get(symbol) > 0) { enc.Write(ctx.Frequencies, symbol); return; } enc.Write(ctx.Frequencies, EscapeSymbol); order--; } enc.Write(model.orderMinus1Freqs, symbol); }