move BitArray in its namerspace
This commit is contained in:
@@ -2,27 +2,47 @@ import { asArray } from "../utils.js";
|
|||||||
import { EmptyBitArray, BitArrayImpl } from "./impl.js";
|
import { EmptyBitArray, BitArrayImpl } from "./impl.js";
|
||||||
import { BitArray } from "./types.js";
|
import { BitArray } from "./types.js";
|
||||||
|
|
||||||
export const EMPTY = new EmptyBitArray();
|
namespace BitArray {
|
||||||
|
export const EMPTY: BitArray = new EmptyBitArray();
|
||||||
|
|
||||||
export function create(length: number): BitArray {
|
export function create(length: number): BitArray {
|
||||||
if (length < 0) {
|
if (length < 0) {
|
||||||
throw new Error("length < 0");
|
throw new Error("length < 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
return length === 0 ? EMPTY : new BitArrayImpl(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return length === 0 ? EMPTY : new BitArrayImpl(length);
|
export function from(bits: Iterable<boolean>) {
|
||||||
}
|
const arr = asArray(bits);
|
||||||
|
const result = create(arr.length);
|
||||||
|
|
||||||
export function from(bits: Iterable<boolean>): BitArray {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
const arr = asArray(bits);
|
result.set(i, arr[i]);
|
||||||
const result = create(arr.length);
|
}
|
||||||
|
|
||||||
for (let i = 0; i < arr.length; i++) {
|
return result;
|
||||||
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 function of(...bits: boolean[]): BitArray {
|
export { BitArray };
|
||||||
return from(bits);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { create as createBitArray } from "../bitarray/index.js";
|
import { BitArray } from "../bitarray/index.js";
|
||||||
import { BitArray } from "../bitarray/types.js";
|
|
||||||
import { asArray } from "../utils.js";
|
import { asArray } from "../utils.js";
|
||||||
import { AsyncRandomOptions, ElementPredicate, ElementWeight, RandomGenerator, RandomOptions } from "./types.js";
|
import { AsyncRandomOptions, ElementPredicate, ElementWeight, RandomGenerator, RandomOptions } from "./types.js";
|
||||||
|
|
||||||
@@ -121,7 +120,7 @@ export class RandomPicker<T> {
|
|||||||
|
|
||||||
public constructor(elements: Iterable<T>, length: number, options?: RandomOptions<T>) {
|
public constructor(elements: Iterable<T>, length: number, options?: RandomOptions<T>) {
|
||||||
this.#elements = elements;
|
this.#elements = elements;
|
||||||
this.#flags = createBitArray(length);
|
this.#flags = BitArray.create(length);
|
||||||
this.#options = withDefaultOptions(mergeOptions({ predicate: i => this.#flags.get(i) }, options));
|
this.#options = withDefaultOptions(mergeOptions({ predicate: i => this.#flags.get(i) }, options));
|
||||||
|
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|||||||
Reference in New Issue
Block a user