fast-boolean-array 1.3.1 → 1.3.3

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/README.md CHANGED
@@ -43,8 +43,10 @@ booleans.set(1, false);
43
43
  console.log(booleans.get(0)); // Output: true
44
44
  console.log(booleans.get(1)); // Output: false
45
45
 
46
- booleans.set(3, false); // will throw as the array is only 3 in size
47
- console.log(booleans.get(1)); // Output: false
46
+ booleans.set(3, true); // will not throw, but returns false as the boolean is not found
47
+ console.log(booleans.get(3)); // Output: false
48
+
49
+ booleans.setSafe(3, true); // will throw out of bounds error
48
50
  ```
49
51
 
50
52
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-boolean-array",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "homepage": "https://github.com/UltraCakeBakery/FastBooleanArray",
5
5
  "repository": {
6
6
  "type": "git",
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
- }
package/test.js DELETED
@@ -1,6 +0,0 @@
1
- import BooleanArray from './dist/index.js';
2
-
3
- const array = new BooleanArray(1);
4
-
5
- const store = array.set(0, true);
6
- console.log(array.get(0), store);