cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
2 lines (1 loc) • 1.73 kB
JavaScript
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t=function(){this.head=null,this.tail=null,this._length=0};t.prototype.insert=function(e){var n=new t.Entry(e);return this.insertEntry(n),n},t.prototype.insertAt=function(e,n){if(!(e<0)){for(var i=this.head,r=0;i&&r!=e;)i=i.next,r++;if(i){var o=new t.Entry(n),h=i.prev;h?(h.next=o,o.prev=h):this.head=o,o.next=i,i.prev=o}else this.insert(n)}},t.prototype.insertBeforeEntry=function(e,n){var i=new t.Entry(e),r=n.prev;r?(r.next=i,i.prev=r):this.head=i,i.next=n,n.prev=i,this._length++},t.prototype.insertEntry=function(t){this.head?(this.tail.next=t,t.prev=this.tail,this.tail=t):this.head=this.tail=t,this._length++},t.prototype.remove=function(t){var e=t.prev,n=t.next;e?e.next=n:this.head=n,n?n.prev=e:this.tail=e,t.next=t.prev=null,this._length--},t.prototype.removeAt=function(t){if(!(t<0)){for(var e=this.head,n=0;e&&n!=t;)e=e.next,n++;return e?(this.remove(e),e.value):void 0}},t.prototype.getHead=function(){if(this.head)return this.head.value},t.prototype.getTail=function(){if(this.tail)return this.tail.value},t.prototype.getAt=function(t){if(!(t<0)){for(var e=this.head,n=0;e&&n!=t;)e=e.next,n++;return e.value}},t.prototype.indexOf=function(t){for(var e=this.head,n=0;e;){if(e.value===t)return n;e=e.next,n++}},t.prototype.length=function(){return this._length},t.prototype.isEmpty=function(){return 0===this._length},t.prototype.forEach=function(t,e){for(var n=this.head,i=0,r=void 0!==e;n;)r?t.call(e,n.value,i):t(n.value,i),n=n.next,i++},t.prototype.clear=function(){this.tail=this.head=null,this._length=0},t.Entry=function(t){this.value=t,this.next=null,this.prev=null};var e=t;exports.default=e;