(function(a,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(a=typeof globalThis<"u"?globalThis:a||self,i(a.Arena={}))})(this,function(a){"use strict";class i{constructor(t=1024){this.array=new Float32Array(t),this.items=[],this.length_used=0,this.length_frag=0,this.array_changed=!1,this.items_pool_length=1024,this.items_pool=Array(1024).fill(0).map(()=>new o(this,0,0))}create(t){return new g(this.create_block(t))}delete(t){if(!t.target)throw new Error("null pointer");t.target.deleted||(t.target.deleted=!0,this.length_frag+=t.target.length,t.target=void 0)}update(t,e){const r=t.target;if(!r)throw new Error("null pointer");if(r.deleted)throw new Error("cannot update deleted memory");const n=e.length;if(n>r.length){const s=this.create_block(e);r.deleted=!0,this.length_frag+=r.length,t.target=s}else this.array.set(e,r.offset),this.length_frag+=r.actual_length-n,r.actual_length=n;this.array_changed=!0}clone(t){const e=t.target;if(!e)throw new Error("null pointer");if(e.deleted)throw new Error("cannot clone deleted memory");const r=e.actual_length;this.malloc(r);const n=this.length_used;this.array.copyWithin(n,e.offset,e.offset+r);const s=new o(this,n,r);return this.length_used+=r,this.array_changed=!0,new g(s)}compact(){const t=this.array,e=this.items,r=[];let n=0;for(let s=0;s=this.length_used+t)return;this.length_frag>e*.25&&this.compact();const r=this.length_used+t;if(e-r<0){e=e===0?16:2*e;const s=new Float32Array(e);s.set(this.array),this.array=s}}create_block(t){const e=t.length;this.malloc(e);const r=this.length_used;this.array.set(t,r);const n=new o(this,r,e);return this.items.push(n),this.length_used+=e,this.array_changed=!0,n}}class o{constructor(t,e,r){this.arena=t,this.offset=e,this.length=r,this.deleted=!1,this.actual_length=r}}class g{constructor(t){this.target=t}get value(){const t=this.target;return t?t.arena.array.subarray(t.offset,t.offset+t.actual_length):null}update(t){const e=this.target;if(!e)throw new Error("null pointer");e.arena.update(this,t)}clone(){const t=this.target;if(!t)throw new Error("null pointer");return t.arena.clone(this)}delete(){const t=this.target;if(!t)throw new Error("null pointer");t.arena.delete(this)}}const u=l=>new i(l);a.arena=u,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});