fast-boolean-array 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +0 -70
- package/test.js +0 -6
package/package.json
CHANGED
package/src/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export default class FastBooleanArray {
|
|
2
|
-
public size: number;
|
|
3
|
-
private buffer: Uint8Array;
|
|
4
|
-
|
|
5
|
-
constructor(size: number) {
|
|
6
|
-
this.size = size;
|
|
7
|
-
this.buffer = new Uint8Array(Math.ceil(size / 8)); // Allocate memory
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Sets a boolean value at the specified index.
|
|
12
|
-
* @param {number} index - The index to set the boolean value at.
|
|
13
|
-
* @param {number} value - The boolean value to set the `index`.
|
|
14
|
-
* @returns {boolean} The boolean value that was set.
|
|
15
|
-
*/
|
|
16
|
-
set(index: number, value: any) {
|
|
17
|
-
if (value) {
|
|
18
|
-
this.buffer[index >> 3] |= 1 << (index & 7); // Set bit
|
|
19
|
-
return true;
|
|
20
|
-
} else {
|
|
21
|
-
this.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
28
|
-
* @param {number} index - The index to set the boolean value at.
|
|
29
|
-
* @param {number} value - The boolean value to set the `index`.
|
|
30
|
-
* @returns {boolean} The boolean value that was set.
|
|
31
|
-
* @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
32
|
-
*/
|
|
33
|
-
setSafe(index: number, value: any) {
|
|
34
|
-
if (index < 0 || index >= this.size) {
|
|
35
|
-
throw new RangeError('Index out of bounds');
|
|
36
|
-
}
|
|
37
|
-
return this.set(index, value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Gets a boolean value at the specified index.
|
|
42
|
-
* @param {number} index - The index to get the boolean value of.
|
|
43
|
-
* @returns {boolean} The boolean value that was set.
|
|
44
|
-
* @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
45
|
-
*/
|
|
46
|
-
get(index: number) {
|
|
47
|
-
return (this.buffer[index >> 3] & (1 << index % 8)) !== 0; // Check bit
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
52
|
-
* @param {number} index - The index to get the boolean value of.
|
|
53
|
-
* @returns {boolean} The boolean value that was set.
|
|
54
|
-
* @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
55
|
-
*/
|
|
56
|
-
getSafe(index: number) {
|
|
57
|
-
if (index < 0 || index >= this.size) {
|
|
58
|
-
throw new RangeError('Index out of bounds');
|
|
59
|
-
}
|
|
60
|
-
return this.get(index);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get length() {
|
|
64
|
-
return this.size;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
set length(_value: number) {
|
|
68
|
-
throw new Error("Setting the length on BooleanArray's is not supported");
|
|
69
|
-
}
|
|
70
|
-
}
|