UNPKG

@data-structure-algebra/doubly-linked-list

Version:
3 lines (2 loc) 11.6 kB
function t(t,e,r){this.value=t,this.prev=e,this.next=r}function e(t,e){t.next=e,e.prev=t}function r(t,r){e(t.prev,r)}function n(){n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},u=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),u=new j(n||[]);return o(i,"_invoke",{value:b(t,r,u)}),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p={};function h(){}function v(){}function y(){}var d={};l(d,u,function(){return this});var x=Object.getPrototypeOf,g=x&&x(x(O([])));g&&g!==e&&r.call(g,u)&&(d=g);var m=y.prototype=h.prototype=Object.create(d);function w(t){["next","throw","return"].forEach(function(e){l(t,e,function(t){return this._invoke(e,t)})})}function _(t,e){function n(o,i,u,a){var c=f(t[o],t,i);if("throw"!==c.type){var l=c.arg,s=l.value;return s&&"object"==typeof s&&r.call(s,"__await")?e.resolve(s.__await).then(function(t){n("next",t,u,a)},function(t){n("throw",t,u,a)}):e.resolve(s).then(function(t){l.value=t,u(l)},function(t){return n("throw",t,u,a)})}a(c.arg)}var i;o(this,"_invoke",{value:function(t,r){function o(){return new e(function(e,o){n(t,r,e,o)})}return i=i?i.then(o,o):o()}})}function b(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var u=r.delegate;if(u){var a=L(u,r);if(a){if(a===p)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function L(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(t){if(t){var e=t[u];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:S}}function S(){return{value:void 0,done:!0}}return v.prototype=y,o(m,"constructor",{value:y,configurable:!0}),o(y,"constructor",{value:v,configurable:!0}),v.displayName=l(y,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,l(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(_.prototype),l(_.prototype,a,function(){return this}),t.AsyncIterator=_,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var u=new _(s(e,r,n,o),i);return t.isGeneratorFunction(r)?u:u.next().then(function(t){return t.done?t.value:u.next()})},w(m),l(m,c,"Generator"),l(m,u,function(){return this}),l(m,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=O,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return u.type="throw",u.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(u)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),k(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function i(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,a=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){c=!0,u=t},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw u}}}}function u(e,r){const n=new t(r,e,null);return e.next=n,n}function a(t,e){let r=t;var n,o=i(e);try{for(o.s();!(n=o.n()).done;)r=u(r,n.value)}catch(t){o.e(t)}finally{o.f()}return r}function c(e,r,n){const o=new t(n,e,r);return e.next=o,r.prev=o,o}var l=/*#__PURE__*/n().mark(s);function s(t){var e,r;return n().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=t;case 1:return e=(r=e).next,n.next=5,r;case 5:if(null!==e){n.next=1;break}case 6:case"end":return n.stop()}},l)}var f=/*#__PURE__*/n().mark(p);function p(t){var e;return n().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:e=t;case 1:return r.next=3,e;case 3:e=e.next;case 4:if(null!==e){r.next=1;break}case 5:case"end":return r.stop()}},f)}function h(t){let e=t;for(;null!==e.next;)e=e.next;return e}function v(t){let e=1,r=t.next;for(;null!==r;)++e,r=r.next;return e}function y(t){const e=t.prev;return e.next=null,e}function d(t){t.prev.next=null,t.prev=null}function x(t,r,n){d(r),e(n,t)}function g(t,e,r){let n=e;for(;--r;)n=n.prev;const o=n.prev;return x(t,n,e),[n,o]}function m(t,e,r,n){const o=n%r;return 0===o?[t,e]:g(t,e,o)}function w(t,e,r){let n=e,o=r;for(;--o;){if(n===t)return m(t,e,r-o,r);n=n.prev}const i=n.prev;return x(t,n,e),[n,i]}function _(t,e,r){let n=t;do{n=n.next}while(--r);const o=n.prev;return x(t,n,e),[n,o]}function b(t,e,r,n){const o=n%r;return 0===o?[t,e]:_(t,e,o)}function L(t,e,r){let n=t,o=r;do{if(n===e)return b(t,e,r-o+1,r);n=n.next}while(--o);const i=n.prev;return x(t,n,e),[n,i]}function E(t){const e=t.next;return e.prev=null,e}function k(e,r){const n=new t(r,null,e);return e.prev=n,n}var j=/*#__PURE__*/n().mark(O);function O(t){return n().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null===t){e.next=2;break}return e.delegateYield(s(t),"t0",2);case 2:case"end":return e.stop()}},j)}function S(t,e,r){return t===e||0===r?[t,e]:r>0?L(t,e,r):w(t,e,-r)}var A=/*#__PURE__*/n().mark(N);function N(t){var e,r,o;return n().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(null===t){n.next=18;break}e=i(p(t)),n.prev=2,e.s();case 4:if((r=e.n()).done){n.next=10;break}return o=r.value,n.next=8,o.value;case 8:n.next=4;break;case 10:n.next=15;break;case 12:n.prev=12,n.t0=n.catch(2),e.e(n.t0);case 15:return n.prev=15,e.f(),n.finish(15);case 18:case"end":return n.stop()}},A,null,[[2,12,15,18]])}exports.Node=t,exports._concat=e,exports._erase=r,exports._extend=a,exports._insertAfter=function(t,e){return c(t,t.next,e)},exports._insertBefore=function(t,e){return c(t.prev,t,e)},exports._insertBetween=c,exports._iter=s,exports._iter_fast=p,exports._last=h,exports._len=v,exports._pop=y,exports._push=u,exports._remove=function(t){r(t,t.next)},exports._rotate_left=g,exports._rotate_left_modulo=m,exports._rotate_left_unknown_length=w,exports._rotate_right=_,exports._rotate_right_modulo=b,exports._rotate_right_unknown_length=L,exports._rotate_to=x,exports._shift=E,exports._split=d,exports._unshift=k,exports.concat=function(t,r,n){return null===t?n:(null===n||e(r,n),t)},exports.empty=function(){return null},exports.from=function(e){const r=e[Symbol.iterator](),n=r.next();if(n.done)return null;const o=new t(n.value,null,null);return a(o,r),o},exports.iter=O,exports.last=function(t){return null===t?null:h(t)},exports.len=t=>null===t?0:v(t),exports.pop=function(t){if(null===t)throw new Error("input list is empty");return[null===t.prev?null:y(t),t]},exports.push=function(e,r,n){return null===e?new t(n,null,null):(u(r,n),e)},exports.rotate_left=(t,e,r)=>S(t,e,-r),exports.rotate_right=S,exports.shift=function(t){if(null===t)throw new Error("input list is empty");return[null===t.next?null:E(t),t]},exports.split=function(t,e){return t===e?[null,t]:null===e?[t,null]:(d(e),[t,e])},exports.unshift=function(e,r){return null===e?new t(r,null,null):k(e,r)},exports.values=N; //# sourceMappingURL=index.cjs.map