/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
class t{constructor(a){if(this.next=null,!Array.isArray(a))return void(this.data=a);this.data=a[0];let e=this;for(let n=1;n<a.length;n++)e.next=new t([a[n]]),e=e.next}*values(){let t=this;for(;t;)yield t.data,t=t.next}forEach(t){let a=this;for(;a;)t(a.data),a=a.next}get last(){return this.next?this.next.last:this}}class a{constructor(a){this._head=null,null!=a&&(this._head=new t(a))}get head(){return this._head}maxAvailableSpace(){if(null==this._head)return 0;let t=0;return this._head.forEach(a=>{const e=a.end-a.start;t=Math.max(t,e)}),t}firstFit(t){if(null==this._head)return null;let a=null,e=this._head;for(;e;){const n=e.data.end-e.data.start;if(n===t)return a?a.next=e.next:this._head=e.next,e.data.start;if(n>t){const a=e.data.start;return e.data.start+=t,a}a=e,e=e.next}return null}free(a,e){const n=a+e;if(null==this._head){const e=new t({start:a,end:n});return void(this._head=e)}if(n<=this._head.data.start){if(n===this._head.data.start)return void(this._head.data.start-=e);const r=new t({start:a,end:n});return r.next=this._head,void(this._head=r)}let r=this._head,d=r.next;for(;d;){if(d.data.start>=n){if(r.data.end===a){if(r.data.end+=e,r.data.end===d.data.start){const t=d.data.end-d.data.start;return r.data.end+=t,void(r.next=d.next)}return}if(d.data.start===n)return void(d.data.start-=e);const s=new t({start:a,end:n});return s.next=r.next,void(r.next=s)}r=d,d=d.next}if(a===r.data.end)return void(r.data.end+=e);const s=new t({start:a,end:n});r.next=s}clear(){this._head=null}}export{a as FreeList,t as List};
