@thi.ng/bitfield
Version:
1D / 2D bit field implementations
74 lines • 2.35 kB
TypeScript
import type { Fn2, IClear, ICopy } from "@thi.ng/api";
import { BitField } from "./bitfield.js";
/**
* MxN row-major 2D bit matrix, backed by a Uint8Array. Hence the width
* (number of columns) is always rounded up to a multiple of 8.
*/
export declare class BitMatrix implements IClear, ICopy<BitMatrix> {
/** Backing byte array */
data: Uint8Array;
/** Number of bytes per row */
stride: number;
/** Number of rows */
m: number;
/** Number of columns */
n: number;
constructor(rows: number, cols?: number);
get length(): number;
clear(): void;
copy(): BitMatrix;
/**
* Resizes matrix to new size given (width always rounded up to
* multiples of 8).
*
* @param m - new number of rows
* @param n - new number of cols
*/
resize(m: number, n?: number): this;
/**
* Returns a non-zero value if bit at `m,n` is enabled (row major).
* No bounds checking.
*
* @param m - row
* @param n - column
*/
at(m: number, n: number): number;
/**
* Enables or disables bit at `m,n` (row major). Returns a non-zero
* value if the bit was previously enabled. No bounds checking.
* .
* @param m - row
* @param n - column
* @param v - bit value
*/
setAt(m: number, n: number, v?: boolean | number): number;
/**
* Inverts bit at `m,n` (row major). Returns a non-zero value if the
* bit was previously enabled. No bounds checking.
*
* @param m - row
* @param n - column
*/
toggleAt(m: number, n: number): number;
and(mat: BitMatrix): this;
or(mat: BitMatrix): this;
xor(mat: BitMatrix): this;
not(): this;
/**
* Returns number of set bits (1's) in the matrix.
*/
popCount(): number;
popCountRow(m: number): number;
popCountColumn(n: number): number;
/**
* Same as {@link BitMatrix.popCount}, but as normalized ratio/percentage.
*/
density(): number;
row(m: number, viewOnly?: boolean): BitField;
column(n: number): BitField;
toString(): string;
protected binOp(field: BitMatrix, op: Fn2<number, number, number>): this;
protected ensureSize(field: BitMatrix): void;
}
export declare const defBitMatrix: (rows: number, cols?: number) => BitMatrix;
//# sourceMappingURL=bitmatrix.d.ts.map