/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function WordArray(length) {
  return new Int32Array(length);
}
const endianConversionView = new DataView(new ArrayBuffer(4));
const endianConversionBytes = new Uint8Array(endianConversionView.buffer);
((WordArray2) => {
  function fromByteArray(bytes, alignment = 1) {
    return fromByteView(new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), alignment);
  }
  WordArray2.fromByteArray = fromByteArray;
  function fromByteView(bytes, alignment = 1) {
    const inputBytes = bytes.byteLength;
    const allocWords = Math.ceil(inputBytes / 4 / alignment) * alignment;
    const result = WordArray2(allocWords);
    let i = 0;
    for (; i + 4 <= inputBytes; i += 4) {
      result[i / 4] = bytes.getInt32(i);
    }
    if (i < inputBytes) {
      result[i / 4] = readPartialWord(bytes, i, inputBytes - i);
    }
    return result;
  }
  WordArray2.fromByteView = fromByteView;
  function bytesToBlock(bytes, block, byteOffset) {
    if (byteOffset === void 0) {
      byteOffset = 0;
    }
    for (let i = 0; i < 4; i++, byteOffset += 4) {
      if (byteOffset + 4 <= bytes.byteLength) {
        block[i] = bytes.getInt32(byteOffset);
      } else if (byteOffset >= bytes.byteLength) {
        block[i] = 0;
      } else {
        block[i] = readPartialWord(bytes, byteOffset);
      }
    }
  }
  WordArray2.bytesToBlock = bytesToBlock;
  function readPartialWord(bytes, offset, bytesAvailable = bytes.byteLength - offset) {
    for (let i = 0; i < 4; i++) {
      if (i < bytesAvailable) {
        endianConversionBytes[i] = bytes.getUint8(offset + i);
      } else {
        endianConversionBytes[i] = 0;
      }
    }
    return endianConversionView.getUint32(0);
  }
  WordArray2.readPartialWord = readPartialWord;
  function writePartialWord(word, bytes, offset, bytesAvailable = Math.max(bytes.byteLength - offset, 4)) {
    endianConversionView.setUint32(0, word);
    endianConversionBytes[0] = word >>> 24;
    endianConversionBytes[1] = word >> 16 & 255;
    endianConversionBytes[2] = word >> 8 & 255;
    endianConversionBytes[3] = word & 255;
    for (let i = 0; i < bytesAvailable; i++) {
      bytes.setUint8(offset + i, endianConversionBytes[i]);
    }
  }
  WordArray2.writePartialWord = writePartialWord;
})(WordArray || (WordArray = {}));
export {
  WordArray
};
//# sourceMappingURL=WordArray.js.map
