UNPKG

@data-structure/deque

Version:
3 lines (2 loc) 7.94 kB
var t=require("@failure-abstraction/error");function n(t,n){(null==n||n>t.length)&&(n=t.length);for(var i=0,r=new Array(n);i<n;i++)r[i]=t[i];return r}function i(t,i){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,i){if(t){if("string"==typeof t)return n(t,i);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)?n(t,i):void 0}}(t))||i&&t&&"number"==typeof t.length){r&&(t=r);var s=0;return function(){return s>=t.length?{done:!0}:{done:!1,value:t[s++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function r(){}function s(){}function e(t,n){this.M=n,this.c=new Array(n),this.x=0,this.length=0,null!==t&&this.extend(t)}function h(t){null!==t&&this.extend(t)}function u(t){this.e=!0,this.v=0,null!==t&&this.extend(t)}function o(t){this.G=2,this.m=10,this.s=this.m,this.c=new Array(this.s),this.x=0,this.length=0,null!==t&&this.extend(t)}function f(n,i,r,s){return function(e,h){if(void 0===e&&(e=null),void 0===h&&(h=null),null===h)return new n(e);if(!Number.isInteger(h))throw new t.TypeError(h);if(0===h)return new s(e);if(1===h)return new r(e);if(h>0)return new i(e,h);throw new t.ValueError(h)}}r.prototype.len=function(){throw new t.NotImplementedError("len")},r.prototype.capacity=function(){throw new t.NotImplementedError("capacity")},r.prototype.empty=function(){return 0===this.len()},r.prototype[Symbol.iterator]=function(){return this.values()},r.prototype.values=function(){throw new t.NotImplementedError("values")},r.prototype.append=function(n){throw new t.NotImplementedError("append")},r.prototype.appendleft=function(n){throw new t.NotImplementedError("appendleft")},r.prototype.clear=function(){throw new t.NotImplementedError("clear")},r.prototype.copy=function(){throw new t.NotImplementedError("copy")},r.prototype.count=function(t){for(var n,r=0,s=i(this);!(n=s()).done;)n.value===t&&++r;return r},r.prototype.extend=function(t){for(var n,r=i(t);!(n=r()).done;)this.append(n.value);return this},r.prototype.extendleft=function(t){for(var n,r=i(t);!(n=r()).done;)this.appendleft(n.value);return this},r.prototype.b=function(n){if(n<0||n>=this.len())throw new t.IndexError(n)},r.prototype.w=function(n){throw new t.NotImplementedError("_where")},r.prototype.get=function(t){var n=this.w(t);return n[0][n[1]]},r.prototype.set=function(t,n){var i=this.w(t);return i[0][i[1]]=n,this},r.prototype.r=regeneratorRuntime.mark(function t(n,i){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:r=n;case 1:if(!(r<i)){t.next=7;break}return t.next=4,[r,this.get(r)];case 4:++r,t.next=1;break;case 7:case"end":return t.stop()}},t,this)}),r.prototype.index=function(n,r,s){void 0===r&&(r=0),void 0===s&&(s=this.len());for(var e,h=i(this.r(r,s));!(e=h()).done;){var u=e.value;if(u[1]===n)return u[0]}throw new t.ValueError("not found")},r.prototype.pop=function(){throw new t.NotImplementedError("pop")},r.prototype.popleft=function(){throw new t.NotImplementedError("popleft")},r.prototype.insert=function(t,n){this.b(t),this.append(n);for(var i=this.len()-1;t<i;--i){var r=this.get(i);this.set(i,this.get(i-1)),this.set(i-1,r)}return this},r.prototype.delete=function(t){this.b(t);for(var n=this.len()-1;t<n;++t)this.set(t,this.get(t+1));return this.pop(),this},r.prototype.remove=function(t){var n=this.index(t);return this.delete(n),this},r.prototype.reverse=function(){for(var t=0,n=this.len();t<--n;++t){var i=this.get(t),r=this.get(n);this.set(t,r),this.set(n,i)}return this},r.prototype.rotate=function(t){if(t>0)for(;t-- >0;)this.appendleft(this.pop());else if(t<0)for(;t++<0;)this.append(this.popleft());return this},(s.prototype=new r).values=regeneratorRuntime.mark(function t(){var n,i,r,s;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:i=(n=this.x)+this.length,r=Math.min(this.capacity(),i);case 3:if(!(n<r)){t.next=9;break}return t.next=6,this.c[n];case 6:++n,t.next=3;break;case 9:if(!((s=i%this.capacity())<i)){t.next=18;break}n=0;case 12:if(!(n<s)){t.next=18;break}return t.next=15,this.c[n];case 15:++n,t.next=12;break;case 18:case"end":return t.stop()}},t,this)}),s.prototype.p=function(n,i){throw new t.NotImplementedError("_popindex")},s.prototype.pop=function(){var t=this.w(this.length-1);return this.p(t[0],t[1])},s.prototype.popleft=function(){var t=this.w(0),n=t[0],i=t[1];return++this.x,this.x%=this.capacity(),this.p(n,i)},(e.prototype=new s).len=function(){return this.length},e.prototype.capacity=function(){return this.M},e.prototype.append=function(t){return this.length===this.M?(this.c[this.x]=t,++this.x,this.x%=this.M):(this.c[(this.x+this.length)%this.M]=t,++this.length),this},e.prototype.appendleft=function(t){return--this.x,this.x+=this.M,this.x%=this.M,this.c[this.x]=t,this.length<this.M&&++this.length,this},e.prototype.clear=function(){return this.x=0,this.length=0,this.c=new Array(this.M),this},e.prototype.copy=function(){return new e(this,this.M)},e.prototype.w=function(t){return this.b(t),[this.c,(this.x+t)%this.M]},e.prototype.p=function(t,n){var i=t[n];return t[n]=0,--this.length,i},(h.prototype=new r).len=function(){return 0},h.prototype.capacity=function(){return 0},h.prototype.values=function(){return{next:function(){return{done:!0}}}},h.prototype.append=function(t){return this},h.prototype.appendleft=function(t){return this},h.prototype.clear=function(){return this},h.prototype.copy=function(){return new h(this)},h.prototype.w=function(n){throw new t.IndexError(n)},h.prototype.pop=h.prototype.popleft=function(){throw new t.IndexError("pop / popleft")},(u.prototype=new r).len=function(){return this.e?0:1},u.prototype.capacity=function(){return 1},u.prototype.values=regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.e){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,this.v;case 4:case"end":return t.stop()}},t,this)}),u.prototype.append=u.prototype.appendleft=function(t){return this.e=!1,this.v=t,this},u.prototype.clear=function(){return this.e=!0,this.v=0,this},u.prototype.copy=function(){return new u(this)},u.prototype.pop=u.prototype.popleft=function(){if(this.e)throw new t.IndexError("pop / popleft");var n=this.v;return this.e=!0,this.v=0,n},u.prototype.get=function(n){if(this.e||0!==n)throw new t.IndexError(n);return this.v},u.prototype.set=function(n,i){if(this.e||0!==n)throw new t.IndexError(n);return this.v=i,this},(o.prototype=new s).y=function(t){for(var n=this.length,i=0;i<n;++i)t[i]=this.get(i)},o.prototype.a=function(t){var n=new Array(t);this.y(n),this.c=n,this.x=0,this.s=t},o.prototype.z=function(){var t=Math.max(this.m,this.length*this.G);t*this.G>=this.s||this.a(t)},o.prototype.g=function(t){t<=this.s||this.a(t*this.G)},o.prototype.len=function(){return this.length},o.prototype.capacity=function(){return this.s},o.prototype.append=function(t){return this.g(this.length+1),this.c[(this.x+this.length)%this.s]=t,++this.length,this},o.prototype.appendleft=function(t){return this.g(this.length+1),--this.x,this.x+=this.s,this.x%=this.s,this.c[this.x]=t,++this.length,this},o.prototype.clear=function(){return this.s=this.m,this.c=new Array(this.s),this.x=0,this.length=0,this},o.prototype.copy=function(){return new o(this)},o.prototype.w=function(t){return this.b(t),[this.c,(this.x+t)%this.s]},o.prototype.p=function(t,n){var i=t[n];return t[n]=0,--this.length,this.z(),i};var c=f(o,e,u,h);exports.ArbitrarySizeDeque=s,exports.BoundedDeque=e,exports.Deque=r,exports.EmptyDeque=h,exports.SingleElementDeque=u,exports.UnboundedDeque=o,exports._deque=f,exports.deque=c; //# sourceMappingURL=index.js.map