@dandre3000/list
Version:
A double linked list class with an API similar to the Array class and a corresponding list node class.
2 lines (1 loc) • 25.1 kB
JavaScript
var R;class T{static[Symbol.hasInstance](z){try{z.#j}catch(q){return!1}return!0}#j;value;[Symbol.toStringTag]=this.constructor.name;constructor(z,q,j=!1){let B,C=null;if(q){try{B=q.#j}catch(H){throw new TypeError(`node argument (${Object.prototype.toString.call(q)}) is not a ListNode instance`)}if(C=B.listData,C&&C.length>=U.maxLength)throw new RangeError(`node.list.length (${C.length}) would exceed List.maxLength (16777216)`)}let G=R=this.#j={node:this,listData:C,previous:null,next:null};if(this.value=z,!B)return;if(!C)new U,B.listData=C=K,C.first=C.last=B,C.length=2,G.listData=C;else C.length++;if(!!j===!0){if(B.next)B.next.previous=G,G.next=B.next;else C.last=G;G.previous=B,B.next=G}else{if(B.previous)B.previous.next=G,G.previous=B.previous;else C.first=G;G.next=B,B.previous=G}}get list(){try{return this.#j.listData?.list||null}catch(z){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a ListNode instance`)}}get previous(){try{return this.#j.previous?.node||null}catch(z){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a ListNode instance`)}}get next(){try{return this.#j.next?.node||null}catch(z){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a ListNode instance`)}}prependTo(z){try{this.#j}catch(G){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a ListNode instance`)}try{z.#j}catch(G){throw new TypeError(`node argument (${Object.prototype.toString.call(z)}) is not a ListNode instance`)}let q=this.#j,j=z.#j,B=j.listData;if(B){if(B.length>=U.maxLength)throw new RangeError(`node.list.length (${B.length}) would exceed List.maxLength (16777216)`);if(q===j.previous)return this}else new U,j.listData=B=K,B.first=j,B.last=j,B.length=1;let C=q.listData;if(C){if(q.previous)q.previous.next=q.next;else C.first=q.next;if(q.next)q.next.previous=q.previous;else C.last=q.previous;C.length--}if(B.length++,q.listData=B,j.previous)j.previous.next=q,q.previous=j.previous;else B.first=q;return q.next=j,j.previous=q,this}appendTo(z){try{this.#j}catch(G){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a ListNode instance`)}let q=this.#j;try{z.#j}catch(G){throw new TypeError(`node argument (${Object.prototype.toString.call(z)}) is not a ListNode instance`)}let j=z.#j,B=j.listData;if(B){if(B.length>=U.maxLength)throw new RangeError(`node.list.length (${B.length}) would exceed List.maxLength (16777216)`);if(q===j.next)return this}else new U,j.listData=B=K,B.first=j,B.last=j,B.length=1;let C=this.#j.listData;if(C){if(q.previous)q.previous.next=q.next;else C.first=q.next;if(q.next)q.next.previous=q.previous;else C.last=q.previous;C.length--}if(B.length++,q.listData=B,j.next)j.next.previous=q,q.next=j.next;else B.last=q;return q.previous=j,j.next=q,this}insertInto(z,q=0){try{this.#j}catch(H){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a ListNode instance`)}if(!(z instanceof U))throw new TypeError(`list argument (${Object.prototype.toString.call(z)}) is not a List instance`);if(K.length>=U.maxLength)throw new RangeError(`list.length (${K.length}) + 1 would exceed List.maxLength (16777216)`);if(q>>=0,q<0||q>K.length)throw new RangeError(`index argument (${q}) is not greater than or equal to 0 and less than or equal to list.length ${K.length}`);let j=this.#j,B=j.listData;if(B){if(j.previous)j.previous.next=j.next;else B.first=j.next;if(j.next)j.next.previous=j.previous;else B.last=j.previous;B.length--}let C=null,G=!1;if(j.listData=K,K.length===0)return K.first=K.last=j,K.length=1,this;if(q===0)C=K.first;else if(q>=K.length-1){if(C=K.last,q===K.length)G=!0}else{let H;if(q<K.length>>>1){C=K.first.next,H=1;while(C){if(q===H)break;C=C.next,H++}}else{C=K.last.previous,H=K.length-2;while(C){if(q===H)break;C=C.previous,H--}}}if(j===C)return this;if(K.length++,G){if(C.next)C.next.previous=j,j.next=C.next;else K.last=j;j.previous=C,C.next=j}else{if(C.previous)C.previous.next=j,j.previous=C.previous;else K.first=j;j.next=C,C.previous=j}return this}remove(){try{this.#j}catch(j){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a ListNode instance`)}let z=this.#j,q=z.listData;if(q){if(z.previous)z.previous.next=z.next;else q.first=z.next;if(z.next)z.next.previous=z.previous;else q.last=z.previous;z.previous=null,z.next=null,q.length--,z.listData=null}return this}}var K;class U{static maxLength=16777216;static from(z,q,j=null){let B=z?.[Symbol.iterator];if(typeof B!=="function")throw new TypeError(`items[Symbol.iterator] (${B}) is not a function`);let C=typeof q;if(q!==void 0&&C!=="function")throw new TypeError(`mapFn argument (${C}) is not a function`);let G=z[Symbol.iterator](),H=G.next(),J=new U;if(H?.done===!0)return J;if(q===void 0){new T(H?.value),K.first=K.last=R,K.length=1,R.listData=K,H=G.next();while(H?.done!==!0)new T(H?.value,R.node,!0),H=G.next()}else{let W=0;new T(q.call(j,H.value,W)),K.first=K.last=R,K.length=1,R.listData=K,H=G.next();while(H.done!==!0)new T(q.call(j,H.value,++W),R.node,!0),H=G.next()}return J}static async fromAsync(z,q,j=null){let B=z?.[Symbol.asyncIterator],C;if(typeof B!=="function"){let Y=z?.[Symbol.iterator];if(typeof Y!=="function")throw new TypeError(`neither items[Symbol.asyncIterator] (${B}) or items[Symbol.iterator] (${Y}) is a function`);C=Symbol.iterator}else C=Symbol.asyncIterator;let G=typeof q;if(q!==void 0&&G!=="function")throw new TypeError(`mapFn argument (${G}) is not a function`);let H=z[C](),J=await H.next(),W=new U,Q,$=new Promise((Y)=>Q=Y);if(J.done===!1)if(q===void 0){new T(J.value),K.first=K.last=R,K.length=1,R.listData=K,J=await H.next();while(J.done!==!0)new T(J.value,R.node,!0),J=await H.next()}else{let Y=0;new T(q.call(j,J.value,Y)),K.first=K.last=R,K.length=1,R.listData=K,J=await H.next();while(J.done!==!0)new T(q.call(j,J.value,++Y),R.node,!0),J=await H.next()}return Q(W),$}static[Symbol.hasInstance](z){try{K=z.#j}catch(q){return!1}return!0}#j;[Symbol.toStringTag]=this.constructor.name;constructor(...z){let q=K=this.#j={list:this,first:null,last:null,length:0},j=z[0];if(z.length===1&&typeof j==="number"){if(!Number.isInteger(j))throw new RangeError(`length argument (${j}) is not an integer`);else if(j<0)throw new RangeError(`length argument (${j}) is less than 0`);else if(j>U.maxLength)throw new RangeError(`length argument (${j}) is greater than List.maxLength (16777216)`);if(j>0)new T(void 0),R.listData=q,q.first=q.last=R,q.length=1;for(let B=1;B<j;B++)new T(void 0,R.node,!0)}else{if(z.length>0)new T(z[0]),R.listData=q,q.first=q.last=R,q.length=1;for(let B=1;B<z.length;B++)new T(z[B],R.node,!0)}}get first(){try{return this.#j.first?.node||null}catch(z){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}}get last(){try{return this.#j.last?.node||null}catch(z){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}}get length(){try{return this.#j.length}catch(z){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}}at(z=0){try{this.#j}catch(B){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let q=this.#j;if(z>>=0,z<0||z>q.length-1)return null;let j;if(z===0)j=q.first;else if(z===q.length-1)j=q.last;else{let B;if(z<q.length>>>1){j=q.first.next,B=1;while(j){if(z===B)break;j=j.next,B++}}else{j=q.last.previous,B=q.length-2;while(j){if(z===B)break;j=j.previous,B--}}}return j.node}unshift(...z){try{this.#j}catch(j){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let q=this.#j;if(q.length+z.length>U.maxLength)throw new RangeError(`this().length (${q.length}) would exceed List.maxLength (16777216)`);if(z.length>0){let j=z.length-1;if(q.length===0)new T(z[j]),R.listData=q,q.first=q.last=R,q.length=1,j--;for(j;j>-1;j--)new T(z[j],q.first.node)}return q.length}push(...z){try{this.#j}catch(j){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let q=this.#j;if(this.#j.length+z.length>U.maxLength)throw new RangeError(`this().length (${q.length}) would exceed List.maxLength (16777216)`);if(z.length>0){let j=0;if(q.length===0)new T(z[j]),R.listData=q,q.first=q.last=R,q.length=1,j=1;for(j;j<z.length;j++)new T(z[j],q.last.node,!0)}return q.length}insert(z=0,...q){try{this.#j}catch(W){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let j=this.#j,B=q.length;if(j.length+B>U.maxLength)throw new RangeError(`this().length (${j.length}) would exceed List.maxLength (16777216)`);if(z>>=0,z<0||z>j.length)throw new RangeError(`index argument (${z}) is not greater than or equal to 0 and less than or equal to this.length (${j.length})`);let C,G=!1,H=B-1;if(z===0){if(j.length===0)new T(q[H]),R.listData=j,j.first=j.last=R,j.length=1,H--;C=j.first}else if(z>=j.length-1){if(C=j.last,z===j.length)G=!0,H=0}else{let W;if(z<j.length>>>1){C=j.first.next,W=1;while(C!==null){if(z===W)break;C=C.next,W++}}else{C=j.last.previous,W=j.length-2;while(C!==null){if(z===W)break;C=C.previous,W--}}}let J=C.node;if(G)for(H;H<B;H++)J=new T(q[H],J,G);else for(H;H>-1;H--)J=new T(q[H],J);return j.length}shift(){try{this.#j}catch(q){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j;if(!z.first)return null;else{let q=z.first;if(q.next)q.next.previous=null,z.first=q.next;else z.first=z.last=null;return z.length--,q.previous=null,q.next=null,q.listData=null,q.node}}pop(){try{this.#j}catch(q){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j;if(!z.last)return null;else{let q=z.last;if(q.previous)q.previous.next=null,z.last=q.previous;else z.first=z.last=null;return z.length--,q.previous=null,q.next=null,q.listData=null,q.node}}remove(z){try{this.#j}catch(B){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let q=this.#j;if(z>>=0,z<0||z>q.length-1)throw new RangeError(`index argument (${z}) is not greater than or equal to 0 and less than this.length (${q.length})`);let j=null;if(z===0)j=q.first;else if(z===q.length-1)j=q.last;else{let B;if(z<q.length>>>1){j=q.first.next,B=1;while(j){if(z===B)break;j=j.next,B++}}else{j=q.last.previous,B=q.length-2;while(j){if(z===B)break;j=j.previous,B--}}}if(j.previous)j.previous.next=j.next;else j.listData.first=j.next;if(j.next)j.next.previous=j.previous;else j.listData.last=j.previous;return j.previous=null,j.next=null,j.listData=null,q.length--,j.node}clear(){try{this.#j}catch(j){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j,q=z.first;z.first=null,z.last=null,z.length=0;while(q){let j=q.next;q.listData=null,q.previous=null,q.next=null,q=j}return this}splice(z=0,q=0,j,B=0){try{this.#j}catch(P){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let C=this.#j;if(z>>=0,z<0||z>C.length-1)throw new RangeError(`start argument (${z}) is not greater than or equal to 0 and less than this.length ${C.length}`);if(q>>=0,q<0||q>C.length-1)throw new RangeError(`end argument (${q}) is not greater than or equal to 0 and less than this.length ${C.length}`);let G=Math.abs(z-q)+1,H;if(j!==void 0){try{this.#j}catch(_){throw new TypeError(`list argument (${Object.prototype.toString.call(j)}) is not a List instance`)}if(H=j.#j,H.length+G>U.maxLength)throw new RangeError(`list.length (${H.length}) would be greater than List.maxLength (16777216)`);let P=C===H?H.length-G:H.length;if(B>>=0,B<0||B>P)throw new RangeError(`target argument (${B}) is not greater than or equal to 0 and less than or equal to list.length minus number of nodes to be moved if list === this (${P})`)}else j=new U,H=j.#j;if(q<z){let P=q;q=z,z=P}let J=null,W=null,Q=null,$=null,Y=null,X;if(z<C.length-q-1){Q=C.first,X=0;while(Q){if(X>=z&&X<=q){if(Q.listData=H,X===z){if(J=Q,Q.previous)$=Q.previous;Q.previous=null}if(X===q){if(W=Q,Q.next)Y=Q.next;Q.next=null;break}}Q=Q.next,X++}}else{Q=C.last,X=C.length-1;while(Q){if(X>=z&&X<=q){if(Q.listData=H,X===q){if(W=Q,Q.next)Y=Q.next;Q.next=null}if(X===z){if(J=Q,Q.previous)$=Q.previous;Q.previous=null;break}}Q=Q.previous,X--}}if($)$.next=Y;else C.first=Y;if(Y)Y.previous=$;else C.last=$;if(C.length-=G,H.length===0)return H.first=J,H.last=W,H.length+=G,H.list;let Z=null,A=!1;if(B===0)Z=H.first;else if(B>=H.length-1){if(Z=H.last,B===H.length)A=!0}else if(B<=H.length>>>1){Q=H.first,X=0;while(Q){if(X===B){Z=Q;break}Q=Q.next,X++}}else{Q=H.last,X=H.length-1;while(Q){if(X===B){Z=Q;break}Q=Q.previous,X--}}if(A){if(Z.next)Z.next.previous=W;else H.last=W;J.previous=Z,W.next=Z.next,Z.next=J}else{if(Z.previous)Z.previous.next=J;else H.first=J;J.previous=Z.previous,W.next=Z,Z.previous=W}return H.length+=G,H.list}fill(z){try{this.#j}catch(B){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let q=this.#j;if(q.length===0)return this;let j=q.first;while(j)j.node.value=z,j=j.next;return this}reverse(){try{this.#j}catch(C){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j;if(z.length===0)return this;let q=z.first;while(q){let{previous:C,next:G}=q;q.previous=G,q.next=C,q=G}let{first:j,last:B}=z;return z.first=B,z.last=j,this}copyWithin(z=0,q=0,j=0,B=!1){try{this.#j}catch($){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let C=this.#j;if(z>>=0,z<0||z>C.length-1)throw new RangeError(`start argument (${z}) is not greater than or equal to 0 and less than this.length (${C.length})`);if(q>>=0,q<0||q>C.length-1)throw new RangeError(`end argument (${q}) is not greater than or equal to 0 and less than this.length (${C.length})`);if(j>>=0,j<0||j>C.length-1)throw new RangeError(`target argument (${j}) is not greater than or equal to 0 and less than this.length (${C.length})`);if(q<z){let $=q;q=z,z=$}if(B=!!B,z===j&&B===!1)return this;else if(q===j&&B===!0)return this;let G,H,J;if(j===0)H=C.first;else if(j===C.length-1)H=C.last;else if(j<C.length>>>1){G=C.first.next,J=1;while(G){if(J===j){H=G;break}G=G.next,J++}}else{G=C.last.previous,J=C.length-2;while(G){if(J===j){H=G;break}G=G.previous,J--}}let W=[],Q=q-z+1;if(z<C.length-q-1){G=C.first,J=0;while(G){if(J>=z&&J<=q){if(W.push(G.node.value),W.length===Q)break}G=G.next,J++}}else{G=C.last,J=C.length-1;while(G){if(J>=z&&J<=q){if(W.unshift(G.node.value),W.length===Q)break}G=G.previous,J--}}if(B===!0)J=W.length-1;else J=0;while(H){if(H.node.value=W[J],B)H=H.previous,J--;else H=H.next,J++;if(J<0||J>W.length-1)break}return this}sort(z){try{this.#j}catch(B){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback (${typeof z} is not a function)`);let q=this.#j;if(q.length<=1)return this;let j=q.first.next;while(j){let B=j.next;while(j.previous!==null&&z(j.previous.node,j.node)>0){let C=j.previous.previous,G=j.previous,H=j.next;if(q.first===G)q.first=j;if(q.last===j)q.last=G;if(C!==null)C.next=j;if(j.previous=C,j.next=G,G.previous=j,G.next=H,H!==null)H.previous=G}j=B}return this}flat(z=1){try{this.#j}catch(B){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(z>>=0,z<1)throw new RangeError(`depth argument (${z}) is not greater than 0`);let q=0,j=[];j.unshift({nodeData:this.#j.first});j:while(j.length>0){let B=j[0],{nodeData:C}=B;while(C){if(B.nodeData=C.next,C.node.value instanceof U&&j.length<=z){j.unshift({nodeData:C.node.value.#j.first});continue j}else if(++q>U.maxLength)throw new RangeError(`this.length (${q}) would exceed List.maxLength (16777216)`);C=B.nodeData}j.shift()}j.unshift({nodeData:this.#j.first});j:while(j.length>0){let{nodeData:B}=j[0];while(B){if(B.node.value instanceof U&&j.length<=z){j.unshift({nodeData:B.node.value.#j.first});continue j}else if(j.length>1)if(j[j.length-1].nodeData.node.value instanceof U)j[j.length-1].nodeData.node.value=B.node.value;else new T(B.node.value,j[j.length-1].nodeData.node,!0),j[j.length-1].nodeData=j[j.length-1].nodeData.next;B=j[0].nodeData=B.next}if(j.shift(),j.length>0)j[0].nodeData=j[0].nodeData.next}return this}slice(z=0,q=this.#j.length-1){try{this.#j}catch(G){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let j=this.#j;if(z>>=0,z<0||z>j.length-1)throw new RangeError(`start argument (${z}) is not greater than or equal to 0 and less than this.length (${j.length})`);if(q>>=0,q<0||q>j.length-1)throw new RangeError(`end argument (${q}) is not greater than or equal to 0 and less than this.length (${j.length})`);if(new U,q<z){let G=q;q=z,z=G}let B=null,C;if(z<j.length-q-1){B=j.first,C=0;while(B){if(C>=z&&C<=q){new T(B.node.value),K.first=K.last=R,K.length=1,R.listData=K,B=B.next,C++;break}B=B.next,C++}while(B){if(C>=z&&C<=q){if(new T(B.node.value,R.node,!0),C===q)break}B=B.next,C++}}else{B=j.last,C=j.length-1;while(B){if(C>=z&&C<=q){new T(B.node.value),K.first=K.last=R,K.length=1,R.listData=K,B=B.previous,C--;break}B=B.previous,C--}while(B){if(C>=z&&C<=q){if(new T(B.node.value,R.node),C===z)break}B=B.previous,C--}}return K.list}includes(z,q=!1){try{this.#j}catch(G){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let j=this.#j;if(j.length===0)return!1;let B=null,C;if(!!q===!0){B=j.last,C=j.length-1;while(B){if(B.node.value===z)return!0;B=B.previous,C--}}else{B=j.first,C=0;while(B){if(B.node.value===z)return!0;B=B.next,C++}}return!1}indexOf(z,q=!1){try{this.#j}catch(G){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let j=this.#j;if(j.length===0)return-1;let B=null,C;if(!!q===!0)B=j.last,C=j.length-1;else B=j.first,C=0;while(B){if(B.node.value===z)return C;if(q)B=B.previous,C--;else B=B.next,C++}return-1}find(z,q=null,j=!1){try{this.#j}catch(H){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let B=this.#j;if(B.length===0)return null;let C=null,G;if(!!j===!0){C=B.last,G=B.length-1;while(C){if(!!z.call(q,C.node,G,this)===!0)return C.node;C=C.previous,G--}}else{C=B.first,G=0;while(C){if(z.call(q,C.node,G,this)===!0)return C.node;C=C.next,G++}}return null}findIndex(z,q=null,j=!1){try{this.#j}catch(H){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let B=this.#j;if(B.length===0)return-1;let C=null,G;if(!!j===!0){C=B.last,G=B.length-1;while(C){if(!!z.call(q,C.node,G,this)===!0)return G;C=C.previous,G--}}else{C=B.first,G=0;while(C){if(!!z.call(q,C.node,G,this)===!0)return G;C=C.next,G++}}return-1}some(z,q=null,j=!1){try{this.#j}catch(H){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let B=this.#j;if(B.length===0)return!1;let C=null,G;if(!!j===!0){C=B.last,G=B.length-1;while(C){if(!!z.call(q,C.node,G,this)===!0)return!0;C=C.previous,G--}}else{C=B.first,G=0;while(C){if(!!z.call(q,C.node,G,this)===!0)return!0;C=C.next,G++}}return!1}every(z,q=null,j=!1){try{this.#j}catch(H){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let B=this.#j;if(B.length===0)return!1;let C=null,G;if(!!j===!0){C=B.last,G=B.length-1;while(C){if(!!z.call(q,C.node,G,this)!==!0)return!1;C=C.previous,G--}}else{C=B.first,G=0;while(C){if(!!z.call(q,C.node,G,this)!==!0)return!1;C=C.next,G++}}return!0}reduce(z,q,j=null,B=!1){try{this.#j}catch(J){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let C=this.#j;if(C.length===0)return q;let G=null,H;if(!!B===!0){G=C.last,H=C.length-1;while(G)q=z.call(j,q,G.node,H,this),G=G.previous,H--}else{G=C.first,H=0;while(G)q=z.call(j,q,G.node,H,this),G=G.next,H++}return q}filter(z,q=null,j=!1){try{this.#j}catch(J){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let B=this.#j;if(B.length===0)return this;let C=[],G=null,H;if(!!j===!0){G=B.last,H=B.length-1;while(G){if(!!z.call(q,G.node,H,this)===!0)C.push(G);G=G.previous,H--}}else{G=B.first,H=0;while(G){if(!!z.call(q,G.node,H,this)===!0)C.push(G);G=G.next,H++}}for(let J of C){if(J.previous)J.previous.next=J.next;else J.listData.first=J.next;if(J.next)J.next.previous=J.previous;else J.listData.last=J.previous;J.previous=null,J.next=null,J.listData=null,B.length--}return this}map(z,q=null,j=!1){try{this.#j}catch(J){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let B=this.#j;if(B.length===0)return this;let C=[],G=null,H;if(!!j===!0){G=B.last,H=B.length-1;while(G)C.push(z.call(q,G.node,H,this)),G=G.previous,H--}else{G=B.first,H=0;while(G)C.push(z.call(q,G.node,H,this)),G=G.next,H++}G=B.first,H=0;while(G)G.node.value=C[H],G=G.next,H++;return this}forEach(z,q=null,j=!1){try{this.#j}catch(H){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}if(typeof z!=="function")throw new TypeError(`callback argument (${typeof z}) is not a function`);let B=this.#j;if(B.length===0)return this;let C=null,G;if(!!j===!0)C=B.last,G=B.length-1;else C=B.first,G=0;while(C)if(z.call(q,C.node,G,this),j)C=C.previous,G--;else C=C.next,G++;return this}concat(...z){try{this.#j}catch(B){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let q=this.#j.length;if(q+z.length===0)return new U;else if(q+z.length>U.maxLength)throw new RangeError(`the new list length (${q+z.length}) would exceed List.maxLength (16777216)`);for(let B of z)if(B instanceof U)q+=B.#j.length;else q++;if(q>U.maxLength)throw new RangeError(`the new list length (${q}) would exceed List.maxLength (16777216)`);let j=null;if(K=null,R=null,this.#j.length>0){j=this.#j.first,new T(j.node.value),j=j.next;while(j)new T(j.node.value,R.node,!0),j=j.next}if(z.length>0){let B=z[0];if(B instanceof U&&B.#j.length>0){j=B.#j.first,new T(j.node.value,R?.node,!0),j=j.next;while(j)new T(j.node.value,R.node,!0),j=j.next}else new T(B,R?.node,!0);for(let C=1;C<z.length;C++)if(B=z[C],B instanceof U){j=B.#j.first;while(j)new T(j.node.value,R.node,!0),j=j.next}else new T(B,R.node,!0)}if(K===null)new U,K.first=K.last=R,K.length=1,R.listData=K;return K.list}nodes(){try{this.#j}catch(C){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j;if(z.length===0)return[];let q=new Array(z.length),j=this.#j.first,B=0;while(j)q[B]=j.node,j=j.next,B++;return q}values(){try{this.#j}catch(C){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j;if(z.length===0)return[];let q=new Array(z.length),j=this.#j.first,B=0;while(j)q[B]=j.node.value,j=j.next,B++;return q}toString(){try{this.#j}catch(G){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j,q="";if(z.length===0)return q;let j=z.first.node.value;q+=typeof j==="object"?Object.prototype.toString.call(j):j;let B=z.first.next,C=1;while(B)j=B.node.value,q+=","+(typeof j==="object"?Object.prototype.toString.call(j):j),B=B.next,C++;return q}[Symbol.iterator](){try{this.#j}catch(C){throw new TypeError(`this (${Object.prototype.toString.call(this)}) is not a List instance`)}let z=this.#j;if(z.length===0)return[][Symbol.iterator]();let q=new Array(z.length),j=this.#j.first,B=0;while(j)q[B]=j.node,j=j.next,B++;return q[Symbol.iterator]()}}Object.defineProperty(T,Symbol.hasInstance,{configurable:!1,writable:!1,enumerable:!1,value:T[Symbol.hasInstance]});Object.defineProperty(U,"maxLength",{configurable:!1,writable:!1,enumerable:!0,value:U.maxLength});Object.defineProperty(U,Symbol.hasInstance,{configurable:!1,writable:!1,enumerable:!1,value:U[Symbol.hasInstance]});var M=Object.getOwnPropertyNames(T.prototype);M.push(...Object.getOwnPropertySymbols(T.prototype));M.forEach((z)=>{let q=Object.getOwnPropertyDescriptor(T.prototype,z);if(q.configurable=!1,q.enumerable=typeof z==="string"?!0:!1,!q.get&&!q.set)q.writable=!1;Object.defineProperty(T.prototype,z,q)});M=Object.getOwnPropertyNames(U.prototype);M.push(...Object.getOwnPropertySymbols(U.prototype));M.forEach((z)=>{let q=Object.getOwnPropertyDescriptor(U.prototype,z);if(q.configurable=!1,q.enumerable=typeof z==="string"?!0:!1,!q.get&&!q.set)q.writable=!1;Object.defineProperty(U.prototype,z,q)});export{T as ListNode,U as List};