ss-linked-list
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="1.1.4"></a> | ||
## [1.1.4](https://github.com/boycgit/ss-linked-list/compare/v1.1.3...v1.1.4) (2018-10-24) | ||
### Features | ||
* **打包:** 将公共依赖包 external 掉 ([9008dd6](https://github.com/boycgit/ss-linked-list/commit/9008dd6)) | ||
<a name="1.1.3"></a> | ||
@@ -7,0 +17,0 @@ ## [1.1.3](https://github.com/boycgit/ss-linked-list/compare/v1.1.0...v1.1.3) (2018-10-22) |
@@ -5,2 +5,6 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var Comparator = _interopDefault(require('ss-comparator')); | ||
var SinglyNode = /** @class */ (function () { | ||
@@ -109,107 +113,2 @@ function SinglyNode(val) { | ||
/** | ||
* enumeration of compare result, there is only three state | ||
* | ||
* @export | ||
* @enum {number} | ||
*/ | ||
var CompareResult; | ||
(function (CompareResult) { | ||
CompareResult[CompareResult["EQUAL"] = 0] = "EQUAL"; | ||
CompareResult[CompareResult["GREATER"] = 1] = "GREATER"; | ||
CompareResult[CompareResult["LESS"] = -1] = "LESS"; | ||
})(CompareResult || (CompareResult = {})); | ||
/** | ||
* a class that describe how compares two object | ||
* | ||
* @export | ||
* @class Comparator | ||
*/ | ||
var Comparator = /** @class */ (function () { | ||
/** | ||
* Creates an instance of Comparator. | ||
* @param {compareFunction} compareFunction - function that implement compare operation | ||
* @memberof Comparator | ||
*/ | ||
function Comparator(compareFunction) { | ||
this.compare = compareFunction || Comparator.defaultCompareFunction; | ||
} | ||
/** | ||
* @param {(string|number)} a - compare target a | ||
* @param {(string|number)} b - compare target b | ||
* @returns {number} | ||
*/ | ||
Comparator.defaultCompareFunction = function (a, b) { | ||
if (a === b) { | ||
return CompareResult.EQUAL; | ||
} | ||
return a < b ? CompareResult.LESS : CompareResult.GREATER; | ||
}; | ||
/** | ||
* compare if equal or not, a === b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.equal = function (a, b) { | ||
return this.compare(a, b) === CompareResult.EQUAL; | ||
}; | ||
/** | ||
* compare if smaller. a < b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.lessThan = function (a, b) { | ||
return this.compare(a, b) === CompareResult.LESS; | ||
}; | ||
/** | ||
* compare if greater. a > b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.greaterThan = function (a, b) { | ||
return this.compare(a, b) === CompareResult.GREATER; | ||
}; | ||
/** | ||
* compare if smaller or equal. a <= b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.lessThanOrEqual = function (a, b) { | ||
return this.lessThan(a, b) || this.equal(a, b); | ||
}; | ||
/** | ||
* compare if greater or equal. a >= b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.greaterThanOrEqual = function (a, b) { | ||
return this.greaterThan(a, b) || this.equal(a, b); | ||
}; | ||
/** | ||
* reverse the compare function | ||
* | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.reverse = function () { | ||
var compareOriginal = this.compare; | ||
this.compare = function (a, b) { return compareOriginal(b, a); }; | ||
}; | ||
return Comparator; | ||
}()); | ||
var List = /** @class */ (function () { | ||
@@ -216,0 +115,0 @@ function List() { |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var SinglyNode=function(t){this.value=t,this.next=null},DoublyNode=function(t){this.value=t,this.next=null,this.prev=null},extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function __extends(t,e){function r(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function __generator(r,n){var i,o,a,t,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;l;)try{if(i=1,o&&(a=2&e[0]?o.return:e[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,e[1])).done)return a;switch(o=0,a&&(e=[2&e[0],a.value]),e[0]){case 0:case 1:a=e;break;case 4:return l.label++,{value:e[1],done:!1};case 5:l.label++,o=e[1],e=[0];continue;case 7:e=l.ops.pop(),l.trys.pop();continue;default:if(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){l=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){l.label=e[1];break}if(6===e[0]&&l.label<a[1]){l.label=a[1],a=e;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(e);break}a[2]&&l.ops.pop(),l.trys.pop();continue}e=n.call(r,l)}catch(t){e=[6,t],o=0}finally{i=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}function __read(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function __spread(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(__read(arguments[e]));return t}var OBFUSCATED_ERROR="obfuse error occur";function invariant(t,e){if(!t)throw new Error("[linked-list] "+(e||OBFUSCATED_ERROR))}var CompareResult,INDEX_NOT_FOUND=-1;!function(t){t[t.EQUAL=0]="EQUAL",t[t.GREATER=1]="GREATER",t[t.LESS=-1]="LESS"}(CompareResult||(CompareResult={}));var Comparator=function(){function e(t){this.compare=t||e.defaultCompareFunction}return e.defaultCompareFunction=function(t,e){return t===e?CompareResult.EQUAL:t<e?CompareResult.LESS:CompareResult.GREATER},e.prototype.equal=function(t,e){return this.compare(t,e)===CompareResult.EQUAL},e.prototype.lessThan=function(t,e){return this.compare(t,e)===CompareResult.LESS},e.prototype.greaterThan=function(t,e){return this.compare(t,e)===CompareResult.GREATER},e.prototype.lessThanOrEqual=function(t,e){return this.lessThan(t,e)||this.equal(t,e)},e.prototype.greaterThanOrEqual=function(t,e){return this.greaterThan(t,e)||this.equal(t,e)},e.prototype.reverse=function(){var r=this.compare;this.compare=function(t,e){return r(e,t)}},e}(),List=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=this;this._head=null,this._tail=null,this._length=0,this.compare=new Comparator,0<t.length&&t.forEach(function(t){r.append(t)})}return Object.defineProperty(t.prototype,"head",{get:function(){return this._head?this._head.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tail",{get:function(){return this._tail?this._tail.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this._length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"loopLength",{get:function(){var t=!1,e=1;if(!this._head)return 0;for(var r=this._head,n=this._head;n.next&&n.next.next;)if(n=n.next.next,(r=r.next)===n){t=!0;break}if(t){for(n=n.next;r!==n;)e++,n=n.next;return e}return 0},enumerable:!0,configurable:!0}),t.prototype.getNode=function(t){var e=this._length;invariant(0<e&&0<=t&&t<e,"[linked-list] index "+t+" out of scope of list, which length is "+e);for(var r=this._head,n=0;n<t;)r=r.next,n++;return r},t.prototype.get=function(t){var e=this.getNode(t);return e?e.value:null},t.prototype.indexOf=function(t){if(!this._head)return INDEX_NOT_FOUND;for(var e=this._head,r=-1;e.next;){if(r++,this.compare.equal(e.value,t))return r;e=e.next}return e===this._tail&&this.compare.equal(e.value,t)&&(r+=1),r},t.prototype.first=function(t){invariant(0<=t,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.iterator(),r=[],n=Math.min(t,this.length),i=0;i<n;i++){var o=e.next();r.push(o.value)}return r},t.prototype.toArray=function(){return __spread(this)},t.prototype.isEmpty=function(){return null===this._head},t.prototype.iterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t}(),SinglyList=function(r){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r.apply(this,__spread(t))||this}return __extends(e,r),e.prototype.append=function(t){var e=new SinglyNode(t);return this._tail?(this._tail.next=e,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new SinglyNode(t);return this._head?(e.next=this._head,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,e.next=null):this._head=this._tail=null,this._length--,t;for(var r=e;;){if(this.compare.equal(e.value,t))return e.next?r.next=e.next:(this._tail=r,this._tail.next=null),e.next=null,this._length--,t;if(!e.next)return;e=(r=e).next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t){if(this._head.next){for(var e=this._head;e.next!==t;)e=e.next;e.next=null,this._tail=e}else this._head=null,this._tail=null;return this._length--,t.value}},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleSinglyList=function(i){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=i.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(t,i),t.prototype.iterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),(e=e.next)===this._head&&(e=null),[3,1];case 3:return[2]}})},t.prototype.circleIterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t.prototype.mapToNormalListFn=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.breakCircle();var n=i.prototype[t].apply(this,e);return this.cyclization(),n},t.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},t.prototype.append=function(t){return this.mapToNormalListFn("append",t)},t.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},t.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},t.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},t.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},t.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},t.prototype.first=function(t){invariant(0<=t,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},t.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},t.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},t}(SinglyList),CircleSinglyList=function(n){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=n.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(e,n),e.prototype.breakCircle=function(){this._tail&&this._tail.next===this._head&&(this._tail.next=null)},e.prototype.cyclization=function(){this._tail&&null===this._tail.next&&(this._tail.next=this._head)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleSinglyList),DoublyList=function(r){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r.apply(this,__spread(t))||this}return __extends(e,r),e.prototype.append=function(t){var e=new DoublyNode(t);return this._tail?((this._tail.next=e).prev=this._tail,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new DoublyNode(t);return this._head?(e.next=this._head,this._head.prev=e,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,this._head.prev=null,e.next=e.prev=null):this._head=this._tail=null,this._length--,t;for(;;){if(this.compare.equal(e.value,t))return e.next?(e.prev.next=e.next,e.next.prev=e.prev):(e.prev.next=null,this._tail=e.prev),e.next=e.prev=null,this._length--,e.value;if(!e.next)return;e=e.next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(t.next.prev=null,this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t)return this._head.next?(t.prev.next=null,this._tail=t.prev,t.next=t.prev=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,e.prev=t,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleDoublyList=function(i){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=i.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(t,i),t.prototype.iterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),(e=e.next)===this._head&&(e=null),[3,1];case 3:return[2]}})},t.prototype.circleIterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t.prototype.mapToNormalListFn=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.breakCircle();var n=i.prototype[t].apply(this,e);return this.cyclization(),n},t.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},t.prototype.append=function(t){return this.mapToNormalListFn("append",t)},t.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},t.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},t.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},t.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},t.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},t.prototype.first=function(t){invariant(0<=t,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},t.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},t.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},t}(DoublyList),CircleDoublyList=function(n){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=n.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(e,n),e.prototype.breakCircle=function(){this._tail&&this._head&&this._tail.next===this._head&&(this._tail.next=null,this._head.prev=null)},e.prototype.cyclization=function(){this._head&&this._tail&&null===this._tail.next&&(this._tail.next=this._head,this._head.prev=this._tail)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleDoublyList);exports.SinglyNode=SinglyNode,exports.DoublyNode=DoublyNode,exports.SinglyList=SinglyList,exports.AbstractCircleSinglyList=AbstractCircleSinglyList,exports.CircleSinglyList=CircleSinglyList,exports.DoublyList=DoublyList,exports.AbstractCircleDoublyList=AbstractCircleDoublyList,exports.CircleDoublyList=CircleDoublyList; | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var Comparator=_interopDefault(require("ss-comparator")),SinglyNode=function(t){this.value=t,this.next=null},DoublyNode=function(t){this.value=t,this.next=null,this.prev=null},extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function __extends(t,e){function r(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function __generator(r,n){var i,o,a,t,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;l;)try{if(i=1,o&&(a=2&e[0]?o.return:e[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,e[1])).done)return a;switch(o=0,a&&(e=[2&e[0],a.value]),e[0]){case 0:case 1:a=e;break;case 4:return l.label++,{value:e[1],done:!1};case 5:l.label++,o=e[1],e=[0];continue;case 7:e=l.ops.pop(),l.trys.pop();continue;default:if(!(a=0<(a=l.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){l=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){l.label=e[1];break}if(6===e[0]&&l.label<a[1]){l.label=a[1],a=e;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(e);break}a[2]&&l.ops.pop(),l.trys.pop();continue}e=n.call(r,l)}catch(t){e=[6,t],o=0}finally{i=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}function __read(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||0<e--)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function __spread(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(__read(arguments[e]));return t}var OBFUSCATED_ERROR="obfuse error occur";function invariant(t,e){if(!t)throw new Error("[linked-list] "+(e||OBFUSCATED_ERROR))}var INDEX_NOT_FOUND=-1,List=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=this;this._head=null,this._tail=null,this._length=0,this.compare=new Comparator,0<t.length&&t.forEach(function(t){r.append(t)})}return Object.defineProperty(t.prototype,"head",{get:function(){return this._head?this._head.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tail",{get:function(){return this._tail?this._tail.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this._length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"loopLength",{get:function(){var t=!1,e=1;if(!this._head)return 0;for(var r=this._head,n=this._head;n.next&&n.next.next;)if(n=n.next.next,(r=r.next)===n){t=!0;break}if(t){for(n=n.next;r!==n;)e++,n=n.next;return e}return 0},enumerable:!0,configurable:!0}),t.prototype.getNode=function(t){var e=this._length;invariant(0<e&&0<=t&&t<e,"[linked-list] index "+t+" out of scope of list, which length is "+e);for(var r=this._head,n=0;n<t;)r=r.next,n++;return r},t.prototype.get=function(t){var e=this.getNode(t);return e?e.value:null},t.prototype.indexOf=function(t){if(!this._head)return INDEX_NOT_FOUND;for(var e=this._head,r=-1;e.next;){if(r++,this.compare.equal(e.value,t))return r;e=e.next}return e===this._tail&&this.compare.equal(e.value,t)&&(r+=1),r},t.prototype.first=function(t){invariant(0<=t,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.iterator(),r=[],n=Math.min(t,this.length),i=0;i<n;i++){var o=e.next();r.push(o.value)}return r},t.prototype.toArray=function(){return __spread(this)},t.prototype.isEmpty=function(){return null===this._head},t.prototype.iterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t}(),SinglyList=function(r){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r.apply(this,__spread(t))||this}return __extends(e,r),e.prototype.append=function(t){var e=new SinglyNode(t);return this._tail?(this._tail.next=e,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new SinglyNode(t);return this._head?(e.next=this._head,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,e.next=null):this._head=this._tail=null,this._length--,t;for(var r=e;;){if(this.compare.equal(e.value,t))return e.next?r.next=e.next:(this._tail=r,this._tail.next=null),e.next=null,this._length--,t;if(!e.next)return;e=(r=e).next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t){if(this._head.next){for(var e=this._head;e.next!==t;)e=e.next;e.next=null,this._tail=e}else this._head=null,this._tail=null;return this._length--,t.value}},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleSinglyList=function(i){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=i.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(t,i),t.prototype.iterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),(e=e.next)===this._head&&(e=null),[3,1];case 3:return[2]}})},t.prototype.circleIterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t.prototype.mapToNormalListFn=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.breakCircle();var n=i.prototype[t].apply(this,e);return this.cyclization(),n},t.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},t.prototype.append=function(t){return this.mapToNormalListFn("append",t)},t.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},t.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},t.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},t.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},t.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},t.prototype.first=function(t){invariant(0<=t,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},t.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},t.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},t}(SinglyList),CircleSinglyList=function(n){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=n.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(e,n),e.prototype.breakCircle=function(){this._tail&&this._tail.next===this._head&&(this._tail.next=null)},e.prototype.cyclization=function(){this._tail&&null===this._tail.next&&(this._tail.next=this._head)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleSinglyList),DoublyList=function(r){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return r.apply(this,__spread(t))||this}return __extends(e,r),e.prototype.append=function(t){var e=new DoublyNode(t);return this._tail?((this._tail.next=e).prev=this._tail,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new DoublyNode(t);return this._head?(e.next=this._head,this._head.prev=e,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,this._head.prev=null,e.next=e.prev=null):this._head=this._tail=null,this._length--,t;for(;;){if(this.compare.equal(e.value,t))return e.next?(e.prev.next=e.next,e.next.prev=e.prev):(e.prev.next=null,this._tail=e.prev),e.next=e.prev=null,this._length--,e.value;if(!e.next)return;e=e.next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(t.next.prev=null,this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t)return this._head.next?(t.prev.next=null,this._tail=t.prev,t.next=t.prev=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,e.prev=t,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleDoublyList=function(i){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=i.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(t,i),t.prototype.iterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),(e=e.next)===this._head&&(e=null),[3,1];case 3:return[2]}})},t.prototype.circleIterator=function(){var e;return __generator(this,function(t){switch(t.label){case 0:e=this._head,t.label=1;case 1:return e?[4,e.value]:[3,3];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t.prototype.mapToNormalListFn=function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];this.breakCircle();var n=i.prototype[t].apply(this,e);return this.cyclization(),n},t.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},t.prototype.append=function(t){return this.mapToNormalListFn("append",t)},t.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},t.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},t.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},t.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},t.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},t.prototype.first=function(t){invariant(0<=t,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},t.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},t.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},t}(DoublyList),CircleDoublyList=function(n){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=n.apply(this,__spread(t))||this;return r.cyclization(),r}return __extends(e,n),e.prototype.breakCircle=function(){this._tail&&this._head&&this._tail.next===this._head&&(this._tail.next=null,this._head.prev=null)},e.prototype.cyclization=function(){this._head&&this._tail&&null===this._tail.next&&(this._tail.next=this._head,this._head.prev=this._tail)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleDoublyList);exports.SinglyNode=SinglyNode,exports.DoublyNode=DoublyNode,exports.SinglyList=SinglyList,exports.AbstractCircleSinglyList=AbstractCircleSinglyList,exports.CircleSinglyList=CircleSinglyList,exports.DoublyList=DoublyList,exports.AbstractCircleDoublyList=AbstractCircleDoublyList,exports.CircleDoublyList=CircleDoublyList; |
@@ -0,1 +1,3 @@ | ||
import Comparator from 'ss-comparator'; | ||
var SinglyNode = /** @class */ (function () { | ||
@@ -104,107 +106,2 @@ function SinglyNode(val) { | ||
/** | ||
* enumeration of compare result, there is only three state | ||
* | ||
* @export | ||
* @enum {number} | ||
*/ | ||
var CompareResult; | ||
(function (CompareResult) { | ||
CompareResult[CompareResult["EQUAL"] = 0] = "EQUAL"; | ||
CompareResult[CompareResult["GREATER"] = 1] = "GREATER"; | ||
CompareResult[CompareResult["LESS"] = -1] = "LESS"; | ||
})(CompareResult || (CompareResult = {})); | ||
/** | ||
* a class that describe how compares two object | ||
* | ||
* @export | ||
* @class Comparator | ||
*/ | ||
var Comparator = /** @class */ (function () { | ||
/** | ||
* Creates an instance of Comparator. | ||
* @param {compareFunction} compareFunction - function that implement compare operation | ||
* @memberof Comparator | ||
*/ | ||
function Comparator(compareFunction) { | ||
this.compare = compareFunction || Comparator.defaultCompareFunction; | ||
} | ||
/** | ||
* @param {(string|number)} a - compare target a | ||
* @param {(string|number)} b - compare target b | ||
* @returns {number} | ||
*/ | ||
Comparator.defaultCompareFunction = function (a, b) { | ||
if (a === b) { | ||
return CompareResult.EQUAL; | ||
} | ||
return a < b ? CompareResult.LESS : CompareResult.GREATER; | ||
}; | ||
/** | ||
* compare if equal or not, a === b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.equal = function (a, b) { | ||
return this.compare(a, b) === CompareResult.EQUAL; | ||
}; | ||
/** | ||
* compare if smaller. a < b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.lessThan = function (a, b) { | ||
return this.compare(a, b) === CompareResult.LESS; | ||
}; | ||
/** | ||
* compare if greater. a > b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.greaterThan = function (a, b) { | ||
return this.compare(a, b) === CompareResult.GREATER; | ||
}; | ||
/** | ||
* compare if smaller or equal. a <= b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.lessThanOrEqual = function (a, b) { | ||
return this.lessThan(a, b) || this.equal(a, b); | ||
}; | ||
/** | ||
* compare if greater or equal. a >= b | ||
* | ||
* @param {*} a | ||
* @param {*} b | ||
* @returns {boolean} | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.greaterThanOrEqual = function (a, b) { | ||
return this.greaterThan(a, b) || this.equal(a, b); | ||
}; | ||
/** | ||
* reverse the compare function | ||
* | ||
* @memberof Comparator | ||
*/ | ||
Comparator.prototype.reverse = function () { | ||
var compareOriginal = this.compare; | ||
this.compare = function (a, b) { return compareOriginal(b, a); }; | ||
}; | ||
return Comparator; | ||
}()); | ||
var List = /** @class */ (function () { | ||
@@ -211,0 +108,0 @@ function List() { |
@@ -1,1 +0,1 @@ | ||
var SinglyNode=function(){return function(t){this.value=t,this.next=null}}(),DoublyNode=function(){return function(t){this.value=t,this.next=null,this.prev=null}}(),extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function __extends(t,e){function r(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function __generator(t,e){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}}function __read(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function __spread(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(__read(arguments[e]));return t}var OBFUSCATED_ERROR="obfuse error occur";function invariant(t,e){if(!t)throw new Error("[linked-list] "+(e||OBFUSCATED_ERROR))}var CompareResult,INDEX_NOT_FOUND=-1;!function(t){t[t.EQUAL=0]="EQUAL",t[t.GREATER=1]="GREATER",t[t.LESS=-1]="LESS"}(CompareResult||(CompareResult={}));var Comparator=function(){function t(e){this.compare=e||t.defaultCompareFunction}return t.defaultCompareFunction=function(t,e){return t===e?CompareResult.EQUAL:t<e?CompareResult.LESS:CompareResult.GREATER},t.prototype.equal=function(t,e){return this.compare(t,e)===CompareResult.EQUAL},t.prototype.lessThan=function(t,e){return this.compare(t,e)===CompareResult.LESS},t.prototype.greaterThan=function(t,e){return this.compare(t,e)===CompareResult.GREATER},t.prototype.lessThanOrEqual=function(t,e){return this.lessThan(t,e)||this.equal(t,e)},t.prototype.greaterThanOrEqual=function(t,e){return this.greaterThan(t,e)||this.equal(t,e)},t.prototype.reverse=function(){var t=this.compare;this.compare=function(e,r){return t(r,e)}},t}(),List=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=this;this._head=null,this._tail=null,this._length=0,this.compare=new Comparator,t.length>0&&t.forEach(function(t){r.append(t)})}return Object.defineProperty(t.prototype,"head",{get:function(){return this._head?this._head.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tail",{get:function(){return this._tail?this._tail.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this._length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"loopLength",{get:function(){var t=!1,e=1;if(!this._head)return 0;for(var r=this._head,n=this._head;n.next&&n.next.next;)if(n=n.next.next,(r=r.next)===n){t=!0;break}if(t){for(n=n.next;r!==n;)e++,n=n.next;return e}return 0},enumerable:!0,configurable:!0}),t.prototype.getNode=function(t){var e=this._length;invariant(e>0&&t>=0&&t<e,"[linked-list] index "+t+" out of scope of list, which length is "+e);for(var r=this._head,n=0;n<t;)r=r.next,n++;return r},t.prototype.get=function(t){var e=this.getNode(t);return e?e.value:null},t.prototype.indexOf=function(t){if(!this._head)return INDEX_NOT_FOUND;for(var e=this._head,r=-1;e.next;){if(r++,this.compare.equal(e.value,t))return r;e=e.next}return e===this._tail&&this.compare.equal(e.value,t)&&(r+=1),r},t.prototype.first=function(t){invariant(t>=0,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.iterator(),r=[],n=Math.min(t,this.length),i=0;i<n;i++){var o=e.next();r.push(o.value)}return r},t.prototype.toArray=function(){return __spread(this)},t.prototype.isEmpty=function(){return null===this._head},t.prototype.iterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t}(),SinglyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.apply(this,__spread(e))||this}return __extends(e,t),e.prototype.append=function(t){var e=new SinglyNode(t);return this._tail?(this._tail.next=e,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new SinglyNode(t);return this._head?(e.next=this._head,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,e.next=null):this._head=this._tail=null,this._length--,t;for(var r=e;;){if(this.compare.equal(e.value,t))return e.next?r.next=e.next:(this._tail=r,this._tail.next=null),e.next=null,this._length--,t;if(!e.next)return;r=e,e=e.next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t){if(this._head.next){for(var e=this._head;e.next!==t;)e=e.next;e.next=null,this._tail=e}else this._head=null,this._tail=null;return this._length--,t.value}},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleSinglyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.iterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),(t=t.next)===this._head&&(t=null),[3,1];case 3:return[2]}})},e.prototype.circleIterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}})},e.prototype[Symbol.iterator]=function(){return this.iterator()},e.prototype.mapToNormalListFn=function(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];this.breakCircle();var i=t.prototype[e].apply(this,r);return this.cyclization(),i},e.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},e.prototype.append=function(t){return this.mapToNormalListFn("append",t)},e.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},e.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},e.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},e.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},e.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},e.prototype.first=function(t){invariant(t>=0,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},e.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},e.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},e}(SinglyList),CircleSinglyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.breakCircle=function(){this._tail&&this._tail.next===this._head&&(this._tail.next=null)},e.prototype.cyclization=function(){this._tail&&null===this._tail.next&&(this._tail.next=this._head)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleSinglyList),DoublyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.apply(this,__spread(e))||this}return __extends(e,t),e.prototype.append=function(t){var e=new DoublyNode(t);return this._tail?(this._tail.next=e,e.prev=this._tail,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new DoublyNode(t);return this._head?(e.next=this._head,this._head.prev=e,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,this._head.prev=null,e.next=e.prev=null):this._head=this._tail=null,this._length--,t;for(;;){if(this.compare.equal(e.value,t))return e.next?(e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null):(e.prev.next=null,this._tail=e.prev,e.next=e.prev=null),this._length--,e.value;if(!e.next)return;e=e.next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(t.next.prev=null,this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t)return this._head.next?(t.prev.next=null,this._tail=t.prev,t.next=t.prev=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,e.prev=t,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleDoublyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.iterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),(t=t.next)===this._head&&(t=null),[3,1];case 3:return[2]}})},e.prototype.circleIterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}})},e.prototype[Symbol.iterator]=function(){return this.iterator()},e.prototype.mapToNormalListFn=function(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];this.breakCircle();var i=t.prototype[e].apply(this,r);return this.cyclization(),i},e.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},e.prototype.append=function(t){return this.mapToNormalListFn("append",t)},e.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},e.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},e.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},e.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},e.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},e.prototype.first=function(t){invariant(t>=0,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},e.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},e.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},e}(DoublyList),CircleDoublyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.breakCircle=function(){this._tail&&this._head&&this._tail.next===this._head&&(this._tail.next=null,this._head.prev=null)},e.prototype.cyclization=function(){this._head&&this._tail&&null===this._tail.next&&(this._tail.next=this._head,this._head.prev=this._tail)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleDoublyList);export{SinglyNode,DoublyNode,SinglyList,AbstractCircleSinglyList,CircleSinglyList,DoublyList,AbstractCircleDoublyList,CircleDoublyList}; | ||
import Comparator from"ss-comparator";var SinglyNode=function(){return function(t){this.value=t,this.next=null}}(),DoublyNode=function(){return function(t){this.value=t,this.next=null,this.prev=null}}(),extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function __extends(t,e){function r(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function __generator(t,e){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}}function __read(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function __spread(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(__read(arguments[e]));return t}var OBFUSCATED_ERROR="obfuse error occur";function invariant(t,e){if(!t)throw new Error("[linked-list] "+(e||OBFUSCATED_ERROR))}var INDEX_NOT_FOUND=-1,List=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=this;this._head=null,this._tail=null,this._length=0,this.compare=new Comparator,t.length>0&&t.forEach(function(t){r.append(t)})}return Object.defineProperty(t.prototype,"head",{get:function(){return this._head?this._head.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tail",{get:function(){return this._tail?this._tail.value:void 0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){return this._length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"loopLength",{get:function(){var t=!1,e=1;if(!this._head)return 0;for(var r=this._head,n=this._head;n.next&&n.next.next;)if(n=n.next.next,(r=r.next)===n){t=!0;break}if(t){for(n=n.next;r!==n;)e++,n=n.next;return e}return 0},enumerable:!0,configurable:!0}),t.prototype.getNode=function(t){var e=this._length;invariant(e>0&&t>=0&&t<e,"[linked-list] index "+t+" out of scope of list, which length is "+e);for(var r=this._head,n=0;n<t;)r=r.next,n++;return r},t.prototype.get=function(t){var e=this.getNode(t);return e?e.value:null},t.prototype.indexOf=function(t){if(!this._head)return INDEX_NOT_FOUND;for(var e=this._head,r=-1;e.next;){if(r++,this.compare.equal(e.value,t))return r;e=e.next}return e===this._tail&&this.compare.equal(e.value,t)&&(r+=1),r},t.prototype.first=function(t){invariant(t>=0,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.iterator(),r=[],n=Math.min(t,this.length),i=0;i<n;i++){var o=e.next();r.push(o.value)}return r},t.prototype.toArray=function(){return __spread(this)},t.prototype.isEmpty=function(){return null===this._head},t.prototype.iterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}})},t.prototype[Symbol.iterator]=function(){return this.iterator()},t}(),SinglyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.apply(this,__spread(e))||this}return __extends(e,t),e.prototype.append=function(t){var e=new SinglyNode(t);return this._tail?(this._tail.next=e,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new SinglyNode(t);return this._head?(e.next=this._head,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,e.next=null):this._head=this._tail=null,this._length--,t;for(var r=e;;){if(this.compare.equal(e.value,t))return e.next?r.next=e.next:(this._tail=r,this._tail.next=null),e.next=null,this._length--,t;if(!e.next)return;r=e,e=e.next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t){if(this._head.next){for(var e=this._head;e.next!==t;)e=e.next;e.next=null,this._tail=e}else this._head=null,this._tail=null;return this._length--,t.value}},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleSinglyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.iterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),(t=t.next)===this._head&&(t=null),[3,1];case 3:return[2]}})},e.prototype.circleIterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}})},e.prototype[Symbol.iterator]=function(){return this.iterator()},e.prototype.mapToNormalListFn=function(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];this.breakCircle();var i=t.prototype[e].apply(this,r);return this.cyclization(),i},e.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},e.prototype.append=function(t){return this.mapToNormalListFn("append",t)},e.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},e.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},e.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},e.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},e.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},e.prototype.first=function(t){invariant(t>=0,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},e.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},e.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},e}(SinglyList),CircleSinglyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.breakCircle=function(){this._tail&&this._tail.next===this._head&&(this._tail.next=null)},e.prototype.cyclization=function(){this._tail&&null===this._tail.next&&(this._tail.next=this._head)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleSinglyList),DoublyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.apply(this,__spread(e))||this}return __extends(e,t),e.prototype.append=function(t){var e=new DoublyNode(t);return this._tail?(this._tail.next=e,e.prev=this._tail,this._tail=e):this._head=this._tail=e,this._length++,!0},e.prototype.prepend=function(t){var e=new DoublyNode(t);return this._head?(e.next=this._head,this._head.prev=e,this._head=e):this._head=this._tail=e,this._length++,!0},e.prototype.remove=function(t){var e=this._head;if(e){if(this.compare.equal(e.value,t))return e.next?(this._head=e.next,this._head.prev=null,e.next=e.prev=null):this._head=this._tail=null,this._length--,t;for(;;){if(this.compare.equal(e.value,t))return e.next?(e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null):(e.prev.next=null,this._tail=e.prev,e.next=e.prev=null),this._length--,e.value;if(!e.next)return;e=e.next}}},e.prototype.removeHead=function(){var t=this._head;if(t)return this._head.next?(t.next.prev=null,this._head=t.next,t.next=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.removeTail=function(){var t=this._tail;if(t)return this._head.next?(t.prev.next=null,this._tail=t.prev,t.next=t.prev=null):(this._head=null,this._tail=null),this._length--,t.value},e.prototype.reverse=function(){if(this._head){var t,e=this._head,r=null;for(this._tail=this._head;null!==e;)t=e.next,e.next=r,e.prev=t,r=e,e=t;this._head=r}},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(List),AbstractCircleDoublyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.iterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),(t=t.next)===this._head&&(t=null),[3,1];case 3:return[2]}})},e.prototype.circleIterator=function(){var t;return __generator(this,function(e){switch(e.label){case 0:t=this._head,e.label=1;case 1:return t?[4,t.value]:[3,3];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}})},e.prototype[Symbol.iterator]=function(){return this.iterator()},e.prototype.mapToNormalListFn=function(e){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];this.breakCircle();var i=t.prototype[e].apply(this,r);return this.cyclization(),i},e.prototype.getNode=function(t){return this.mapToNormalListFn("getNode",t)},e.prototype.append=function(t){return this.mapToNormalListFn("append",t)},e.prototype.prepend=function(t){return this.mapToNormalListFn("prepend",t)},e.prototype.indexOf=function(t){return this.mapToNormalListFn("indexOf",t)},e.prototype.remove=function(t){return this.mapToNormalListFn("remove",t)},e.prototype.removeHead=function(){return this.mapToNormalListFn("removeHead")},e.prototype.removeTail=function(){return this.mapToNormalListFn("removeTail")},e.prototype.first=function(t){invariant(t>=0,"[linked-list] param 'num' ("+t+") should not less than 0");for(var e=this.circleIterator(),r=[],n=0;n<t;n++){var i=e.next();r.push(i.value)}return r},e.prototype.toArray=function(){return this.mapToNormalListFn("toArray")},e.prototype.reverse=function(){return this.mapToNormalListFn("reverse")},e}(DoublyList),CircleDoublyList=function(t){function e(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var n=t.apply(this,__spread(e))||this;return n.cyclization(),n}return __extends(e,t),e.prototype.breakCircle=function(){this._tail&&this._head&&this._tail.next===this._head&&(this._tail.next=null,this._head.prev=null)},e.prototype.cyclization=function(){this._head&&this._tail&&null===this._tail.next&&(this._tail.next=this._head,this._head.prev=this._tail)},e.prototype.clone=function(){var t=this.toArray();return new(e.bind.apply(e,__spread([void 0],t)))},e}(AbstractCircleDoublyList);export{SinglyNode,DoublyNode,SinglyList,AbstractCircleSinglyList,CircleSinglyList,DoublyList,AbstractCircleDoublyList,CircleDoublyList}; |
{ | ||
"name": "ss-linked-list", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"main": "dist/index.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.esm.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
140836
2815
2