d8bf11979d1ca7404b7537d1eb04778a3242300cc38ef77bd0f067ff40d5e54f089124e9d82d5a2d264f117a4f0c2adeaa0327f518e407bd5e981e8e7fca07 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. var __extends = this && this.t || function() {
  2. var extendStatics = function(t, i) {
  3. extendStatics = Object.setPrototypeOf || {
  4. __proto__: []
  5. } instanceof Array && function(t, i) {
  6. t.__proto__ = i;
  7. } || function(t, i) {
  8. for (var r in i) if (Object.prototype.hasOwnProperty.call(i, r)) t[r] = i[r];
  9. };
  10. return extendStatics(t, i);
  11. };
  12. return function(t, i) {
  13. if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null");
  14. extendStatics(t, i);
  15. function __() {
  16. this.constructor = t;
  17. }
  18. t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __);
  19. };
  20. }();
  21. var __generator = this && this.i || function(t, i) {
  22. var r = {
  23. label: 0,
  24. sent: function() {
  25. if (e[0] & 1) throw e[1];
  26. return e[1];
  27. },
  28. trys: [],
  29. ops: []
  30. }, n, s, e, h;
  31. return h = {
  32. next: verb(0),
  33. throw: verb(1),
  34. return: verb(2)
  35. }, typeof Symbol === "function" && (h[Symbol.iterator] = function() {
  36. return this;
  37. }), h;
  38. function verb(t) {
  39. return function(i) {
  40. return step([ t, i ]);
  41. };
  42. }
  43. function step(h) {
  44. if (n) throw new TypeError("Generator is already executing.");
  45. while (r) try {
  46. if (n = 1, s && (e = h[0] & 2 ? s["return"] : h[0] ? s["throw"] || ((e = s["return"]) && e.call(s),
  47. 0) : s.next) && !(e = e.call(s, h[1])).done) return e;
  48. if (s = 0, e) h = [ h[0] & 2, e.value ];
  49. switch (h[0]) {
  50. case 0:
  51. case 1:
  52. e = h;
  53. break;
  54. case 4:
  55. r.label++;
  56. return {
  57. value: h[1],
  58. done: false
  59. };
  60. case 5:
  61. r.label++;
  62. s = h[1];
  63. h = [ 0 ];
  64. continue;
  65. case 7:
  66. h = r.ops.pop();
  67. r.trys.pop();
  68. continue;
  69. default:
  70. if (!(e = r.trys, e = e.length > 0 && e[e.length - 1]) && (h[0] === 6 || h[0] === 2)) {
  71. r = 0;
  72. continue;
  73. }
  74. if (h[0] === 3 && (!e || h[1] > e[0] && h[1] < e[3])) {
  75. r.label = h[1];
  76. break;
  77. }
  78. if (h[0] === 6 && r.label < e[1]) {
  79. r.label = e[1];
  80. e = h;
  81. break;
  82. }
  83. if (e && r.label < e[2]) {
  84. r.label = e[2];
  85. r.ops.push(h);
  86. break;
  87. }
  88. if (e[2]) r.ops.pop();
  89. r.trys.pop();
  90. continue;
  91. }
  92. h = i.call(t, r);
  93. } catch (t) {
  94. h = [ 6, t ];
  95. s = 0;
  96. } finally {
  97. n = e = 0;
  98. }
  99. if (h[0] & 5) throw h[1];
  100. return {
  101. value: h[0] ? h[1] : void 0,
  102. done: true
  103. };
  104. }
  105. };
  106. import SequentialContainer from "./Base";
  107. import { ContainerIterator } from "../ContainerBase";
  108. import { throwIteratorAccessError } from "../../utils/throwError";
  109. var LinkListIterator = function(t) {
  110. __extends(LinkListIterator, t);
  111. function LinkListIterator(i, r, n, s) {
  112. var e = t.call(this, s) || this;
  113. e.o = i;
  114. e.h = r;
  115. e.container = n;
  116. if (e.iteratorType === 0) {
  117. e.pre = function() {
  118. if (this.o.L === this.h) {
  119. throwIteratorAccessError();
  120. }
  121. this.o = this.o.L;
  122. return this;
  123. };
  124. e.next = function() {
  125. if (this.o === this.h) {
  126. throwIteratorAccessError();
  127. }
  128. this.o = this.o.m;
  129. return this;
  130. };
  131. } else {
  132. e.pre = function() {
  133. if (this.o.m === this.h) {
  134. throwIteratorAccessError();
  135. }
  136. this.o = this.o.m;
  137. return this;
  138. };
  139. e.next = function() {
  140. if (this.o === this.h) {
  141. throwIteratorAccessError();
  142. }
  143. this.o = this.o.L;
  144. return this;
  145. };
  146. }
  147. return e;
  148. }
  149. Object.defineProperty(LinkListIterator.prototype, "pointer", {
  150. get: function() {
  151. if (this.o === this.h) {
  152. throwIteratorAccessError();
  153. }
  154. return this.o.p;
  155. },
  156. set: function(t) {
  157. if (this.o === this.h) {
  158. throwIteratorAccessError();
  159. }
  160. this.o.p = t;
  161. },
  162. enumerable: false,
  163. configurable: true
  164. });
  165. LinkListIterator.prototype.copy = function() {
  166. return new LinkListIterator(this.o, this.h, this.container, this.iteratorType);
  167. };
  168. return LinkListIterator;
  169. }(ContainerIterator);
  170. var LinkList = function(t) {
  171. __extends(LinkList, t);
  172. function LinkList(i) {
  173. if (i === void 0) {
  174. i = [];
  175. }
  176. var r = t.call(this) || this;
  177. r.h = {};
  178. r.H = r.l = r.h.L = r.h.m = r.h;
  179. var n = r;
  180. i.forEach((function(t) {
  181. n.pushBack(t);
  182. }));
  183. return r;
  184. }
  185. LinkList.prototype.G = function(t) {
  186. var i = t.L, r = t.m;
  187. i.m = r;
  188. r.L = i;
  189. if (t === this.H) {
  190. this.H = r;
  191. }
  192. if (t === this.l) {
  193. this.l = i;
  194. }
  195. this.M -= 1;
  196. };
  197. LinkList.prototype.F = function(t, i) {
  198. var r = i.m;
  199. var n = {
  200. p: t,
  201. L: i,
  202. m: r
  203. };
  204. i.m = n;
  205. r.L = n;
  206. if (i === this.h) {
  207. this.H = n;
  208. }
  209. if (r === this.h) {
  210. this.l = n;
  211. }
  212. this.M += 1;
  213. };
  214. LinkList.prototype.clear = function() {
  215. this.M = 0;
  216. this.H = this.l = this.h.L = this.h.m = this.h;
  217. };
  218. LinkList.prototype.begin = function() {
  219. return new LinkListIterator(this.H, this.h, this);
  220. };
  221. LinkList.prototype.end = function() {
  222. return new LinkListIterator(this.h, this.h, this);
  223. };
  224. LinkList.prototype.rBegin = function() {
  225. return new LinkListIterator(this.l, this.h, this, 1);
  226. };
  227. LinkList.prototype.rEnd = function() {
  228. return new LinkListIterator(this.h, this.h, this, 1);
  229. };
  230. LinkList.prototype.front = function() {
  231. return this.H.p;
  232. };
  233. LinkList.prototype.back = function() {
  234. return this.l.p;
  235. };
  236. LinkList.prototype.getElementByPos = function(t) {
  237. if (t < 0 || t > this.M - 1) {
  238. throw new RangeError;
  239. }
  240. var i = this.H;
  241. while (t--) {
  242. i = i.m;
  243. }
  244. return i.p;
  245. };
  246. LinkList.prototype.eraseElementByPos = function(t) {
  247. if (t < 0 || t > this.M - 1) {
  248. throw new RangeError;
  249. }
  250. var i = this.H;
  251. while (t--) {
  252. i = i.m;
  253. }
  254. this.G(i);
  255. return this.M;
  256. };
  257. LinkList.prototype.eraseElementByValue = function(t) {
  258. var i = this.H;
  259. while (i !== this.h) {
  260. if (i.p === t) {
  261. this.G(i);
  262. }
  263. i = i.m;
  264. }
  265. return this.M;
  266. };
  267. LinkList.prototype.eraseElementByIterator = function(t) {
  268. var i = t.o;
  269. if (i === this.h) {
  270. throwIteratorAccessError();
  271. }
  272. t = t.next();
  273. this.G(i);
  274. return t;
  275. };
  276. LinkList.prototype.pushBack = function(t) {
  277. this.F(t, this.l);
  278. return this.M;
  279. };
  280. LinkList.prototype.popBack = function() {
  281. if (this.M === 0) return;
  282. var t = this.l.p;
  283. this.G(this.l);
  284. return t;
  285. };
  286. LinkList.prototype.pushFront = function(t) {
  287. this.F(t, this.h);
  288. return this.M;
  289. };
  290. LinkList.prototype.popFront = function() {
  291. if (this.M === 0) return;
  292. var t = this.H.p;
  293. this.G(this.H);
  294. return t;
  295. };
  296. LinkList.prototype.setElementByPos = function(t, i) {
  297. if (t < 0 || t > this.M - 1) {
  298. throw new RangeError;
  299. }
  300. var r = this.H;
  301. while (t--) {
  302. r = r.m;
  303. }
  304. r.p = i;
  305. };
  306. LinkList.prototype.insert = function(t, i, r) {
  307. if (r === void 0) {
  308. r = 1;
  309. }
  310. if (t < 0 || t > this.M) {
  311. throw new RangeError;
  312. }
  313. if (r <= 0) return this.M;
  314. if (t === 0) {
  315. while (r--) this.pushFront(i);
  316. } else if (t === this.M) {
  317. while (r--) this.pushBack(i);
  318. } else {
  319. var n = this.H;
  320. for (var s = 1; s < t; ++s) {
  321. n = n.m;
  322. }
  323. var e = n.m;
  324. this.M += r;
  325. while (r--) {
  326. n.m = {
  327. p: i,
  328. L: n
  329. };
  330. n.m.L = n;
  331. n = n.m;
  332. }
  333. n.m = e;
  334. e.L = n;
  335. }
  336. return this.M;
  337. };
  338. LinkList.prototype.find = function(t) {
  339. var i = this.H;
  340. while (i !== this.h) {
  341. if (i.p === t) {
  342. return new LinkListIterator(i, this.h, this);
  343. }
  344. i = i.m;
  345. }
  346. return this.end();
  347. };
  348. LinkList.prototype.reverse = function() {
  349. if (this.M <= 1) return;
  350. var t = this.H;
  351. var i = this.l;
  352. var r = 0;
  353. while (r << 1 < this.M) {
  354. var n = t.p;
  355. t.p = i.p;
  356. i.p = n;
  357. t = t.m;
  358. i = i.L;
  359. r += 1;
  360. }
  361. };
  362. LinkList.prototype.unique = function() {
  363. if (this.M <= 1) {
  364. return this.M;
  365. }
  366. var t = this.H;
  367. while (t !== this.h) {
  368. var i = t;
  369. while (i.m !== this.h && i.p === i.m.p) {
  370. i = i.m;
  371. this.M -= 1;
  372. }
  373. t.m = i.m;
  374. t.m.L = t;
  375. t = t.m;
  376. }
  377. return this.M;
  378. };
  379. LinkList.prototype.sort = function(t) {
  380. if (this.M <= 1) return;
  381. var i = [];
  382. this.forEach((function(t) {
  383. i.push(t);
  384. }));
  385. i.sort(t);
  386. var r = this.H;
  387. i.forEach((function(t) {
  388. r.p = t;
  389. r = r.m;
  390. }));
  391. };
  392. LinkList.prototype.merge = function(t) {
  393. var i = this;
  394. if (this.M === 0) {
  395. t.forEach((function(t) {
  396. i.pushBack(t);
  397. }));
  398. } else {
  399. var r = this.H;
  400. t.forEach((function(t) {
  401. while (r !== i.h && r.p <= t) {
  402. r = r.m;
  403. }
  404. i.F(t, r.L);
  405. }));
  406. }
  407. return this.M;
  408. };
  409. LinkList.prototype.forEach = function(t) {
  410. var i = this.H;
  411. var r = 0;
  412. while (i !== this.h) {
  413. t(i.p, r++, this);
  414. i = i.m;
  415. }
  416. };
  417. LinkList.prototype[Symbol.iterator] = function() {
  418. return function() {
  419. var t;
  420. return __generator(this, (function(i) {
  421. switch (i.label) {
  422. case 0:
  423. if (this.M === 0) return [ 2 ];
  424. t = this.H;
  425. i.label = 1;
  426. case 1:
  427. if (!(t !== this.h)) return [ 3, 3 ];
  428. return [ 4, t.p ];
  429. case 2:
  430. i.sent();
  431. t = t.m;
  432. return [ 3, 1 ];
  433. case 3:
  434. return [ 2 ];
  435. }
  436. }));
  437. }.bind(this)();
  438. };
  439. return LinkList;
  440. }(SequentialContainer);
  441. export default LinkList;
  442. //# sourceMappingURL=LinkList.js.map