import { asArray } from "../utils.js"; import { EmptyBitArray, BitArrayImpl } from "./impl.js"; import { BitArray } from "./types.js"; namespace BitArray { export const EMPTY: BitArray = new EmptyBitArray(); export function create(length: number): BitArray { if (length < 0) { throw new Error("length < 0"); } return length === 0 ? EMPTY : new BitArrayImpl(length); } export function from(bits: Iterable) { const arr = asArray(bits); const result = create(arr.length); for (let i = 0; i < arr.length; i++) { result.set(i, arr[i]); } return result; } export function of(...bits: boolean[]) { return from(bits); } export function and(a: BitArray, b: BitArray) { return a.copy().and(b); } export function or(a: BitArray, b: BitArray) { return a.copy().or(b); } export function xor(a: BitArray, b: BitArray) { return a.copy().xor(b); } export function not(a: BitArray) { return a.copy().not(); } } export { BitArray };