var __defProp = Object.defineProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
  __markAsModule(target);
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __accessCheck = (obj, member, msg) => {
  if (!member.has(obj))
    throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
  __accessCheck(obj, member, "read from private field");
  return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
  if (member.has(obj))
    throw TypeError("Cannot add the same private member more than once");
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
__export(exports, {
  default: () => Allocator
});
var _wasm, _base;
let wasm;
{
  const module2 = new WebAssembly.Module(require('fs').readFileSync(require('path').join(__dirname, '../../src/alloc/simd.wasm')));
  wasm = () => new WebAssembly.Instance(module2).exports;
}
class Allocator {
  constructor() {
    __privateAdd(this, _wasm, wasm());
    __privateAdd(this, _base, __privateGet(this, _wasm).memory.buffer.byteLength);
  }
  get memory() {
    return __privateGet(this, _wasm).memory;
  }
  alloc(size) {
    return __privateGet(this, _wasm).walloc(size);
  }
  free(ptr) {
    return __privateGet(this, _wasm).wfree(ptr, this.size(ptr));
  }
  size(ptr) {
    return new Uint32Array(__privateGet(this, _wasm).memory.buffer)[ptr / 4 - 1];
  }
  u8(ptr, size) {
    return new Uint8Array(__privateGet(this, _wasm).memory.buffer, ptr, size);
  }
  get stats() {
    const buffer = __privateGet(this, _wasm).memory.buffer;
    return {
      total: buffer.byteLength,
      heap: buffer.byteLength - __privateGet(this, _base)
    };
  }
}
_wasm = new WeakMap();
_base = new WeakMap();
