FreqData.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Text;
  3. using SharpCompress.Converters;
  4. namespace SharpCompress.Compressors.PPMd.H
  5. {
  6. internal class FreqData : Pointer
  7. {
  8. internal const int SIZE = 6;
  9. // struct FreqData
  10. // {
  11. // ushort SummFreq;
  12. // STATE _PACK_ATTR * Stats;
  13. // };
  14. internal FreqData(byte[] memory)
  15. : base(memory)
  16. {
  17. }
  18. internal int SummFreq { get => DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff; set => DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value); }
  19. internal FreqData Initialize(byte[] mem)
  20. {
  21. return base.Initialize<FreqData>(mem);
  22. }
  23. internal void IncrementSummFreq(int dSummFreq)
  24. {
  25. short summFreq = DataConverter.LittleEndian.GetInt16(Memory, Address);
  26. summFreq += (short)dSummFreq;
  27. DataConverter.LittleEndian.PutBytes(Memory, Address, summFreq);
  28. }
  29. internal int GetStats()
  30. {
  31. return DataConverter.LittleEndian.GetInt32(Memory, Address + 2);
  32. }
  33. internal virtual void SetStats(State state)
  34. {
  35. SetStats(state.Address);
  36. }
  37. internal void SetStats(int state)
  38. {
  39. DataConverter.LittleEndian.PutBytes(Memory, Address + 2, state);
  40. }
  41. public override String ToString()
  42. {
  43. StringBuilder buffer = new StringBuilder();
  44. buffer.Append("FreqData[");
  45. buffer.Append("\n Address=");
  46. buffer.Append(Address);
  47. buffer.Append("\n size=");
  48. buffer.Append(SIZE);
  49. buffer.Append("\n summFreq=");
  50. buffer.Append(SummFreq);
  51. buffer.Append("\n stats=");
  52. buffer.Append(GetStats());
  53. buffer.Append("\n]");
  54. return buffer.ToString();
  55. }
  56. }
  57. }