73b2b6f7b59fbee77afc133bdac246d5bb44979fe833a176a0b6f2e9f8bf852e2d7740211ac46379272e69fe7f136751e18626506fb0231462094d318ecf70 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. "use strict";
  2. Object.defineProperty(exports, "t", {
  3. value: true
  4. });
  5. exports.HashContainerIterator = exports.HashContainer = void 0;
  6. var _ContainerBase = require("../../ContainerBase");
  7. var _checkObject = _interopRequireDefault(require("../../../utils/checkObject"));
  8. var _throwError = require("../../../utils/throwError");
  9. function _interopRequireDefault(t) {
  10. return t && t.t ? t : {
  11. default: t
  12. };
  13. }
  14. class HashContainerIterator extends _ContainerBase.ContainerIterator {
  15. constructor(t, e, i) {
  16. super(i);
  17. this.o = t;
  18. this.h = e;
  19. if (this.iteratorType === 0) {
  20. this.pre = function() {
  21. if (this.o.L === this.h) {
  22. (0, _throwError.throwIteratorAccessError)();
  23. }
  24. this.o = this.o.L;
  25. return this;
  26. };
  27. this.next = function() {
  28. if (this.o === this.h) {
  29. (0, _throwError.throwIteratorAccessError)();
  30. }
  31. this.o = this.o.B;
  32. return this;
  33. };
  34. } else {
  35. this.pre = function() {
  36. if (this.o.B === this.h) {
  37. (0, _throwError.throwIteratorAccessError)();
  38. }
  39. this.o = this.o.B;
  40. return this;
  41. };
  42. this.next = function() {
  43. if (this.o === this.h) {
  44. (0, _throwError.throwIteratorAccessError)();
  45. }
  46. this.o = this.o.L;
  47. return this;
  48. };
  49. }
  50. }
  51. }
  52. exports.HashContainerIterator = HashContainerIterator;
  53. class HashContainer extends _ContainerBase.Container {
  54. constructor() {
  55. super();
  56. this.H = [];
  57. this.g = {};
  58. this.HASH_TAG = Symbol("@@HASH_TAG");
  59. Object.setPrototypeOf(this.g, null);
  60. this.h = {};
  61. this.h.L = this.h.B = this.p = this._ = this.h;
  62. }
  63. V(t) {
  64. const {L: e, B: i} = t;
  65. e.B = i;
  66. i.L = e;
  67. if (t === this.p) {
  68. this.p = i;
  69. }
  70. if (t === this._) {
  71. this._ = e;
  72. }
  73. this.i -= 1;
  74. }
  75. M(t, e, i) {
  76. if (i === undefined) i = (0, _checkObject.default)(t);
  77. let s;
  78. if (i) {
  79. const i = t[this.HASH_TAG];
  80. if (i !== undefined) {
  81. this.H[i].l = e;
  82. return this.i;
  83. }
  84. Object.defineProperty(t, this.HASH_TAG, {
  85. value: this.H.length,
  86. configurable: true
  87. });
  88. s = {
  89. u: t,
  90. l: e,
  91. L: this._,
  92. B: this.h
  93. };
  94. this.H.push(s);
  95. } else {
  96. const i = this.g[t];
  97. if (i) {
  98. i.l = e;
  99. return this.i;
  100. }
  101. s = {
  102. u: t,
  103. l: e,
  104. L: this._,
  105. B: this.h
  106. };
  107. this.g[t] = s;
  108. }
  109. if (this.i === 0) {
  110. this.p = s;
  111. this.h.B = s;
  112. } else {
  113. this._.B = s;
  114. }
  115. this._ = s;
  116. this.h.L = s;
  117. return ++this.i;
  118. }
  119. I(t, e) {
  120. if (e === undefined) e = (0, _checkObject.default)(t);
  121. if (e) {
  122. const e = t[this.HASH_TAG];
  123. if (e === undefined) return this.h;
  124. return this.H[e];
  125. } else {
  126. return this.g[t] || this.h;
  127. }
  128. }
  129. clear() {
  130. const t = this.HASH_TAG;
  131. this.H.forEach((function(e) {
  132. delete e.u[t];
  133. }));
  134. this.H = [];
  135. this.g = {};
  136. Object.setPrototypeOf(this.g, null);
  137. this.i = 0;
  138. this.p = this._ = this.h.L = this.h.B = this.h;
  139. }
  140. eraseElementByKey(t, e) {
  141. let i;
  142. if (e === undefined) e = (0, _checkObject.default)(t);
  143. if (e) {
  144. const e = t[this.HASH_TAG];
  145. if (e === undefined) return false;
  146. delete t[this.HASH_TAG];
  147. i = this.H[e];
  148. delete this.H[e];
  149. } else {
  150. i = this.g[t];
  151. if (i === undefined) return false;
  152. delete this.g[t];
  153. }
  154. this.V(i);
  155. return true;
  156. }
  157. eraseElementByIterator(t) {
  158. const e = t.o;
  159. if (e === this.h) {
  160. (0, _throwError.throwIteratorAccessError)();
  161. }
  162. this.V(e);
  163. return t.next();
  164. }
  165. eraseElementByPos(t) {
  166. if (t < 0 || t > this.i - 1) {
  167. throw new RangeError;
  168. }
  169. let e = this.p;
  170. while (t--) {
  171. e = e.B;
  172. }
  173. this.V(e);
  174. return this.i;
  175. }
  176. }
  177. exports.HashContainer = HashContainer;
  178. //# sourceMappingURL=index.js.map