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