UNPKG

1.73 kBTypeScriptView Raw
1interface BitFieldOptions {
2 /**
3 * If you `set` an index that is out-of-bounds, the bitfield
4 * will automatically grow so that the bitfield is big enough
5 * to contain the given index, up to the given size (in bit).
6 *
7 * If you want the Bitfield to grow indefinitely, pass `Infinity`.
8 *
9 * @default 0.
10 */
11 grow?: number;
12}
13export default class BitField {
14 /**
15 * Grow the bitfield up to this number of entries.
16 * @default 0.
17 */
18 private readonly grow;
19 /** The internal storage of the bitfield. */
20 buffer: Uint8Array;
21 /**
22 *
23 *
24 * @param data Either a number representing the maximum number of supported bytes, or a Uint8Array.
25 * @param opts Options for the bitfield.
26 */
27 constructor(data?: number | Uint8Array, opts?: BitFieldOptions);
28 /**
29 * Get a particular bit.
30 *
31 * @param i Bit index to retrieve.
32 * @returns A boolean indicating whether the `i`th bit is set.
33 */
34 get(i: number): boolean;
35 /**
36 * Set a particular bit.
37 *
38 * Will grow the underlying array if the bit is out of bounds and the `grow` option is set.
39 *
40 * @param i Bit index to set.
41 * @param value Value to set the bit to. Defaults to `true`.
42 */
43 set(i: number, value?: boolean): void;
44 /**
45 * Loop through the bits in the bitfield.
46 *
47 * @param fn Function to be called with the bit value and index.
48 * @param start Index of the first bit to look at.
49 * @param end Index of the first bit that should no longer be considered.
50 */
51 forEach(fn: (bit: boolean, index: number) => void, start?: number, end?: number): void;
52}
53export {};
54//# sourceMappingURL=index.d.ts.map
\No newline at end of file