| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- var __extends = this && this.t || function() {
- var extendStatics = function(t, i) {
- extendStatics = Object.setPrototypeOf || {
- __proto__: []
- } instanceof Array && function(t, i) {
- t.__proto__ = i;
- } || function(t, i) {
- for (var r in i) if (Object.prototype.hasOwnProperty.call(i, r)) t[r] = i[r];
- };
- return extendStatics(t, i);
- };
- return function(t, i) {
- if (typeof i !== "function" && i !== null) throw new TypeError("Class extends value " + String(i) + " is not a constructor or null");
- extendStatics(t, i);
- function __() {
- this.constructor = t;
- }
- t.prototype = i === null ? Object.create(i) : (__.prototype = i.prototype, new __);
- };
- }();
- var __generator = this && this.i || function(t, i) {
- var r = {
- label: 0,
- sent: function() {
- if (e[0] & 1) throw e[1];
- return e[1];
- },
- trys: [],
- ops: []
- }, n, s, e, h;
- return h = {
- next: verb(0),
- throw: verb(1),
- return: verb(2)
- }, typeof Symbol === "function" && (h[Symbol.iterator] = function() {
- return this;
- }), h;
- function verb(t) {
- return function(i) {
- return step([ t, i ]);
- };
- }
- function step(h) {
- if (n) throw new TypeError("Generator is already executing.");
- while (r) try {
- if (n = 1, s && (e = h[0] & 2 ? s["return"] : h[0] ? s["throw"] || ((e = s["return"]) && e.call(s),
- 0) : s.next) && !(e = e.call(s, h[1])).done) return e;
- if (s = 0, e) h = [ h[0] & 2, e.value ];
- switch (h[0]) {
- case 0:
- case 1:
- e = h;
- break;
- case 4:
- r.label++;
- return {
- value: h[1],
- done: false
- };
- case 5:
- r.label++;
- s = h[1];
- h = [ 0 ];
- continue;
- case 7:
- h = r.ops.pop();
- r.trys.pop();
- continue;
- default:
- if (!(e = r.trys, e = e.length > 0 && e[e.length - 1]) && (h[0] === 6 || h[0] === 2)) {
- r = 0;
- continue;
- }
- if (h[0] === 3 && (!e || h[1] > e[0] && h[1] < e[3])) {
- r.label = h[1];
- break;
- }
- if (h[0] === 6 && r.label < e[1]) {
- r.label = e[1];
- e = h;
- break;
- }
- if (e && r.label < e[2]) {
- r.label = e[2];
- r.ops.push(h);
- break;
- }
- if (e[2]) r.ops.pop();
- r.trys.pop();
- continue;
- }
- h = i.call(t, r);
- } catch (t) {
- h = [ 6, t ];
- s = 0;
- } finally {
- n = e = 0;
- }
- if (h[0] & 5) throw h[1];
- return {
- value: h[0] ? h[1] : void 0,
- done: true
- };
- }
- };
- import SequentialContainer from "./Base";
- import { ContainerIterator } from "../ContainerBase";
- import { throwIteratorAccessError } from "../../utils/throwError";
- var LinkListIterator = function(t) {
- __extends(LinkListIterator, t);
- function LinkListIterator(i, r, n, s) {
- var e = t.call(this, s) || this;
- e.o = i;
- e.h = r;
- e.container = n;
- if (e.iteratorType === 0) {
- e.pre = function() {
- if (this.o.L === this.h) {
- throwIteratorAccessError();
- }
- this.o = this.o.L;
- return this;
- };
- e.next = function() {
- if (this.o === this.h) {
- throwIteratorAccessError();
- }
- this.o = this.o.m;
- return this;
- };
- } else {
- e.pre = function() {
- if (this.o.m === this.h) {
- throwIteratorAccessError();
- }
- this.o = this.o.m;
- return this;
- };
- e.next = function() {
- if (this.o === this.h) {
- throwIteratorAccessError();
- }
- this.o = this.o.L;
- return this;
- };
- }
- return e;
- }
- Object.defineProperty(LinkListIterator.prototype, "pointer", {
- get: function() {
- if (this.o === this.h) {
- throwIteratorAccessError();
- }
- return this.o.p;
- },
- set: function(t) {
- if (this.o === this.h) {
- throwIteratorAccessError();
- }
- this.o.p = t;
- },
- enumerable: false,
- configurable: true
- });
- LinkListIterator.prototype.copy = function() {
- return new LinkListIterator(this.o, this.h, this.container, this.iteratorType);
- };
- return LinkListIterator;
- }(ContainerIterator);
- var LinkList = function(t) {
- __extends(LinkList, t);
- function LinkList(i) {
- if (i === void 0) {
- i = [];
- }
- var r = t.call(this) || this;
- r.h = {};
- r.H = r.l = r.h.L = r.h.m = r.h;
- var n = r;
- i.forEach((function(t) {
- n.pushBack(t);
- }));
- return r;
- }
- LinkList.prototype.G = function(t) {
- var i = t.L, r = t.m;
- i.m = r;
- r.L = i;
- if (t === this.H) {
- this.H = r;
- }
- if (t === this.l) {
- this.l = i;
- }
- this.M -= 1;
- };
- LinkList.prototype.F = function(t, i) {
- var r = i.m;
- var n = {
- p: t,
- L: i,
- m: r
- };
- i.m = n;
- r.L = n;
- if (i === this.h) {
- this.H = n;
- }
- if (r === this.h) {
- this.l = n;
- }
- this.M += 1;
- };
- LinkList.prototype.clear = function() {
- this.M = 0;
- this.H = this.l = this.h.L = this.h.m = this.h;
- };
- LinkList.prototype.begin = function() {
- return new LinkListIterator(this.H, this.h, this);
- };
- LinkList.prototype.end = function() {
- return new LinkListIterator(this.h, this.h, this);
- };
- LinkList.prototype.rBegin = function() {
- return new LinkListIterator(this.l, this.h, this, 1);
- };
- LinkList.prototype.rEnd = function() {
- return new LinkListIterator(this.h, this.h, this, 1);
- };
- LinkList.prototype.front = function() {
- return this.H.p;
- };
- LinkList.prototype.back = function() {
- return this.l.p;
- };
- LinkList.prototype.getElementByPos = function(t) {
- if (t < 0 || t > this.M - 1) {
- throw new RangeError;
- }
- var i = this.H;
- while (t--) {
- i = i.m;
- }
- return i.p;
- };
- LinkList.prototype.eraseElementByPos = function(t) {
- if (t < 0 || t > this.M - 1) {
- throw new RangeError;
- }
- var i = this.H;
- while (t--) {
- i = i.m;
- }
- this.G(i);
- return this.M;
- };
- LinkList.prototype.eraseElementByValue = function(t) {
- var i = this.H;
- while (i !== this.h) {
- if (i.p === t) {
- this.G(i);
- }
- i = i.m;
- }
- return this.M;
- };
- LinkList.prototype.eraseElementByIterator = function(t) {
- var i = t.o;
- if (i === this.h) {
- throwIteratorAccessError();
- }
- t = t.next();
- this.G(i);
- return t;
- };
- LinkList.prototype.pushBack = function(t) {
- this.F(t, this.l);
- return this.M;
- };
- LinkList.prototype.popBack = function() {
- if (this.M === 0) return;
- var t = this.l.p;
- this.G(this.l);
- return t;
- };
- LinkList.prototype.pushFront = function(t) {
- this.F(t, this.h);
- return this.M;
- };
- LinkList.prototype.popFront = function() {
- if (this.M === 0) return;
- var t = this.H.p;
- this.G(this.H);
- return t;
- };
- LinkList.prototype.setElementByPos = function(t, i) {
- if (t < 0 || t > this.M - 1) {
- throw new RangeError;
- }
- var r = this.H;
- while (t--) {
- r = r.m;
- }
- r.p = i;
- };
- LinkList.prototype.insert = function(t, i, r) {
- if (r === void 0) {
- r = 1;
- }
- if (t < 0 || t > this.M) {
- throw new RangeError;
- }
- if (r <= 0) return this.M;
- if (t === 0) {
- while (r--) this.pushFront(i);
- } else if (t === this.M) {
- while (r--) this.pushBack(i);
- } else {
- var n = this.H;
- for (var s = 1; s < t; ++s) {
- n = n.m;
- }
- var e = n.m;
- this.M += r;
- while (r--) {
- n.m = {
- p: i,
- L: n
- };
- n.m.L = n;
- n = n.m;
- }
- n.m = e;
- e.L = n;
- }
- return this.M;
- };
- LinkList.prototype.find = function(t) {
- var i = this.H;
- while (i !== this.h) {
- if (i.p === t) {
- return new LinkListIterator(i, this.h, this);
- }
- i = i.m;
- }
- return this.end();
- };
- LinkList.prototype.reverse = function() {
- if (this.M <= 1) return;
- var t = this.H;
- var i = this.l;
- var r = 0;
- while (r << 1 < this.M) {
- var n = t.p;
- t.p = i.p;
- i.p = n;
- t = t.m;
- i = i.L;
- r += 1;
- }
- };
- LinkList.prototype.unique = function() {
- if (this.M <= 1) {
- return this.M;
- }
- var t = this.H;
- while (t !== this.h) {
- var i = t;
- while (i.m !== this.h && i.p === i.m.p) {
- i = i.m;
- this.M -= 1;
- }
- t.m = i.m;
- t.m.L = t;
- t = t.m;
- }
- return this.M;
- };
- LinkList.prototype.sort = function(t) {
- if (this.M <= 1) return;
- var i = [];
- this.forEach((function(t) {
- i.push(t);
- }));
- i.sort(t);
- var r = this.H;
- i.forEach((function(t) {
- r.p = t;
- r = r.m;
- }));
- };
- LinkList.prototype.merge = function(t) {
- var i = this;
- if (this.M === 0) {
- t.forEach((function(t) {
- i.pushBack(t);
- }));
- } else {
- var r = this.H;
- t.forEach((function(t) {
- while (r !== i.h && r.p <= t) {
- r = r.m;
- }
- i.F(t, r.L);
- }));
- }
- return this.M;
- };
- LinkList.prototype.forEach = function(t) {
- var i = this.H;
- var r = 0;
- while (i !== this.h) {
- t(i.p, r++, this);
- i = i.m;
- }
- };
- LinkList.prototype[Symbol.iterator] = function() {
- return function() {
- var t;
- return __generator(this, (function(i) {
- switch (i.label) {
- case 0:
- if (this.M === 0) return [ 2 ];
- t = this.H;
- i.label = 1;
- case 1:
- if (!(t !== this.h)) return [ 3, 3 ];
- return [ 4, t.p ];
- case 2:
- i.sent();
- t = t.m;
- return [ 3, 1 ];
- case 3:
- return [ 2 ];
- }
- }));
- }.bind(this)();
- };
- return LinkList;
- }(SequentialContainer);
- export default LinkList;
- //# sourceMappingURL=LinkList.js.map
|