/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
const t=1.25;class r{get length(){return this._pos}constructor(t,r){this._pos=0;const e=r?this._roundToNearest(r,t.BYTES_PER_ELEMENT):40;this._array=new ArrayBuffer(e),this._buffer=new t(this._array),this._ctor=t,this._i16View=new Int16Array(this._array)}_roundToNearest(t,r){const e=Math.round(t);return 1===r?e:e+(r-e%r)}_ensureSize(r){if(this._pos+r>=this._buffer.length){const e=this._roundToNearest((this._array.byteLength+r*this._buffer.BYTES_PER_ELEMENT)*t,this._buffer.BYTES_PER_ELEMENT),s=new ArrayBuffer(e),i=new this._ctor(s);i.set(this._buffer,0),this._array=s,this._buffer=i,this._i16View=new Int16Array(this._array)}}ensureSize(t){this._ensureSize(t)}writeF32(t){this._ensureSize(1);const r=this._pos;return new Float32Array(this._array,4*this._pos,1)[0]=t,this._pos++,r}push(t){this._ensureSize(1);const r=this._pos;return this._buffer[this._pos++]=t,r}writeFixed(t){this._buffer[this._pos++]=t}setValue(t,r){this._buffer[t]=r}i1616Add(t,r,e){this._i16View[2*t]+=r,this._i16View[2*t+1]+=e}getValue(t){return this._buffer[t]}getValueF32(t){return new Float32Array(this._array,4*t,1)[0]}incr(t){if(this._buffer.length<t)throw new Error("Increment index overflows the target buffer");this._buffer[t]++}decr(t){this._buffer[t]--}writeRegion(t){this._ensureSize(t.length);const r=this._pos;return this._buffer.set(t,this._pos),this._pos+=t.length,r}writeManyFrom(t,r,e){this._ensureSize(e-r);for(let s=r;s!==e;s++)this.writeFixed(t._buffer[s])}buffer(){const t=this._array.slice(0,4*this._pos);return this.destroy(),t}toArray(){return[...this._buffer]}seek(t){this._pos=t}destroy(){this._array=null,this._buffer=null}}export{r as default};
