StateRef.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Text;
  3. namespace SharpCompress.Compressors.PPMd.H
  4. {
  5. internal class StateRef
  6. {
  7. private int _symbol;
  8. private int _freq;
  9. private int _successor; // pointer ppmcontext
  10. internal int Symbol { get => _symbol; set => _symbol = value & 0xff; }
  11. internal int Freq { get => _freq; set => _freq = value & 0xff; }
  12. internal State Values
  13. {
  14. set
  15. {
  16. Freq = value.Freq;
  17. SetSuccessor(value.GetSuccessor());
  18. Symbol = value.Symbol;
  19. }
  20. }
  21. public virtual void IncrementFreq(int dFreq)
  22. {
  23. _freq = (_freq + dFreq) & 0xff;
  24. }
  25. public virtual void DecrementFreq(int dFreq)
  26. {
  27. _freq = (_freq - dFreq) & 0xff;
  28. }
  29. public virtual int GetSuccessor()
  30. {
  31. return _successor;
  32. }
  33. public virtual void SetSuccessor(PpmContext successor)
  34. {
  35. SetSuccessor(successor.Address);
  36. }
  37. public virtual void SetSuccessor(int successor)
  38. {
  39. _successor = successor;
  40. }
  41. public override String ToString()
  42. {
  43. StringBuilder buffer = new StringBuilder();
  44. buffer.Append("State[");
  45. buffer.Append("\n symbol=");
  46. buffer.Append(Symbol);
  47. buffer.Append("\n freq=");
  48. buffer.Append(Freq);
  49. buffer.Append("\n successor=");
  50. buffer.Append(GetSuccessor());
  51. buffer.Append("\n]");
  52. return buffer.ToString();
  53. }
  54. }
  55. }