SEE2Context.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Text;
  3. namespace SharpCompress.Compressors.PPMd.H
  4. {
  5. internal class See2Context
  6. {
  7. public virtual int Mean
  8. {
  9. get
  10. {
  11. int retVal = Utility.URShift(_summ, _shift);
  12. _summ -= retVal;
  13. return retVal + ((retVal == 0) ? 1 : 0);
  14. }
  15. }
  16. public virtual int Count { get => _count; set => _count = value & 0xff; }
  17. public virtual int Shift { get => _shift; set => _shift = value & 0xff; }
  18. public virtual int Summ { get => _summ; set => _summ = value & 0xffff; }
  19. public const int SIZE = 4;
  20. // ushort Summ;
  21. private int _summ;
  22. // byte Shift;
  23. private int _shift;
  24. // byte Count;
  25. private int _count;
  26. public void Initialize(int initVal)
  27. {
  28. _shift = (ModelPpm.PERIOD_BITS - 4) & 0xff;
  29. _summ = (initVal << _shift) & 0xffff;
  30. _count = 4;
  31. }
  32. public virtual void Update()
  33. {
  34. if (_shift < ModelPpm.PERIOD_BITS && --_count == 0)
  35. {
  36. _summ += _summ;
  37. _count = (3 << _shift++);
  38. }
  39. _summ &= 0xffff;
  40. _count &= 0xff;
  41. _shift &= 0xff;
  42. }
  43. public virtual void IncSumm(int dSumm)
  44. {
  45. Summ = Summ + dSumm;
  46. }
  47. public override String ToString()
  48. {
  49. StringBuilder buffer = new StringBuilder();
  50. buffer.Append("SEE2Context[");
  51. buffer.Append("\n size=");
  52. buffer.Append(SIZE);
  53. buffer.Append("\n summ=");
  54. buffer.Append(_summ);
  55. buffer.Append("\n shift=");
  56. buffer.Append(_shift);
  57. buffer.Append("\n count=");
  58. buffer.Append(_count);
  59. buffer.Append("\n]");
  60. return buffer.ToString();
  61. }
  62. }
  63. }