RarMemBlock.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using SharpCompress.Converters;
  2. namespace SharpCompress.Compressors.PPMd.H
  3. {
  4. internal class RarMemBlock : Pointer
  5. {
  6. public const int SIZE = 12;
  7. private int _stamp, _nu;
  8. private int _next, _prev; // Pointer RarMemBlock
  9. public RarMemBlock(byte[] memory)
  10. : base(memory)
  11. {
  12. }
  13. internal int Stamp
  14. {
  15. get
  16. {
  17. if (Memory != null)
  18. {
  19. _stamp = DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff;
  20. }
  21. return _stamp;
  22. }
  23. set
  24. {
  25. _stamp = value;
  26. if (Memory != null)
  27. {
  28. DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value);
  29. }
  30. }
  31. }
  32. internal void InsertAt(RarMemBlock p)
  33. {
  34. RarMemBlock temp = new RarMemBlock(Memory);
  35. SetPrev(p.Address);
  36. temp.Address = GetPrev();
  37. SetNext(temp.GetNext()); // prev.getNext();
  38. temp.SetNext(this); // prev.setNext(this);
  39. temp.Address = GetNext();
  40. temp.SetPrev(this); // next.setPrev(this);
  41. }
  42. internal void Remove()
  43. {
  44. RarMemBlock temp = new RarMemBlock(Memory);
  45. temp.Address = GetPrev();
  46. temp.SetNext(GetNext()); // prev.setNext(next);
  47. temp.Address = GetNext();
  48. temp.SetPrev(GetPrev()); // next.setPrev(prev);
  49. // next = -1;
  50. // prev = -1;
  51. }
  52. internal int GetNext()
  53. {
  54. if (Memory != null)
  55. {
  56. _next = DataConverter.LittleEndian.GetInt32(Memory, Address + 4);
  57. }
  58. return _next;
  59. }
  60. internal void SetNext(RarMemBlock next)
  61. {
  62. SetNext(next.Address);
  63. }
  64. internal void SetNext(int next)
  65. {
  66. _next = next;
  67. if (Memory != null)
  68. {
  69. DataConverter.LittleEndian.PutBytes(Memory, Address + 4, next);
  70. }
  71. }
  72. internal int GetNu()
  73. {
  74. if (Memory != null)
  75. {
  76. _nu = DataConverter.LittleEndian.GetInt16(Memory, Address + 2) & 0xffff;
  77. }
  78. return _nu;
  79. }
  80. internal void SetNu(int nu)
  81. {
  82. _nu = nu & 0xffff;
  83. if (Memory != null)
  84. {
  85. DataConverter.LittleEndian.PutBytes(Memory, Address + 2, (short)nu);
  86. }
  87. }
  88. internal int GetPrev()
  89. {
  90. if (Memory != null)
  91. {
  92. _prev = DataConverter.LittleEndian.GetInt32(Memory, Address + 8);
  93. }
  94. return _prev;
  95. }
  96. internal void SetPrev(RarMemBlock prev)
  97. {
  98. SetPrev(prev.Address);
  99. }
  100. internal void SetPrev(int prev)
  101. {
  102. _prev = prev;
  103. if (Memory != null)
  104. {
  105. DataConverter.LittleEndian.PutBytes(Memory, Address + 8, prev);
  106. }
  107. }
  108. }
  109. }