move BitArray in its namerspace
This commit is contained in:
@@ -2,7 +2,8 @@ import { asArray } from "../utils.js";
|
||||
import { EmptyBitArray, BitArrayImpl } from "./impl.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 {
|
||||
if (length < 0) {
|
||||
@@ -12,7 +13,7 @@ export function create(length: number): BitArray {
|
||||
return length === 0 ? EMPTY : new BitArrayImpl(length);
|
||||
}
|
||||
|
||||
export function from(bits: Iterable<boolean>): BitArray {
|
||||
export function from(bits: Iterable<boolean>) {
|
||||
const arr = asArray(bits);
|
||||
const result = create(arr.length);
|
||||
|
||||
@@ -23,6 +24,25 @@ export function from(bits: Iterable<boolean>): BitArray {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function of(...bits: boolean[]): BitArray {
|
||||
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 };
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { create as createBitArray } from "../bitarray/index.js";
|
||||
import { BitArray } from "../bitarray/types.js";
|
||||
import { BitArray } from "../bitarray/index.js";
|
||||
import { asArray } from "../utils.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>) {
|
||||
this.#elements = elements;
|
||||
this.#flags = createBitArray(length);
|
||||
this.#flags = BitArray.create(length);
|
||||
this.#options = withDefaultOptions(mergeOptions({ predicate: i => this.#flags.get(i) }, options));
|
||||
|
||||
this.reset();
|
||||
|
||||
Reference in New Issue
Block a user