fast-boolean-array 1.1.2 → 1.2.1

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
@@ -15,6 +15,7 @@ View detailed benchmark results below.
15
15
  ## Installation
16
16
 
17
17
  Install the package via npm:
18
+
18
19
  ```bash
19
20
  npm install fast-boolean-array
20
21
  ```
@@ -26,21 +27,22 @@ npm install fast-boolean-array
26
27
  Here's how to use the Fast Boolean Array:
27
28
 
28
29
  ```javascript
29
- const BooleanArray = require('fast-boolean-array');
30
+ import BooleanArray from 'fast-boolean-array';
31
+ // const BooleanArray = require('fast-boolean-array'); works too
30
32
 
31
33
  // Create a new BooleanArray with the desired size
32
- const booleans = new BooleanArray(10);
34
+ const booleans = new BooleanArray(2);
33
35
 
34
36
  // Set a value at a specific index
35
37
  booleans.set(0, true);
38
+ booleans.set(1, false);
36
39
 
37
- // Get the value at a specific index
40
+ // Retrieve it
38
41
  console.log(booleans.get(0)); // Output: true
42
+ console.log(booleans.get(1)); // Output: false
39
43
 
40
- // Set another value
41
- booleans.set(1, false);
42
44
 
43
- // Retrieve it
45
+ booleans.set(3, false); // will throw as the array is only 3 in size
44
46
  console.log(booleans.get(1)); // Output: false
45
47
  ```
46
48
 
@@ -49,12 +51,14 @@ console.log(booleans.get(1)); // Output: false
49
51
  ## API
50
52
 
51
53
  ### `new BooleanArray(size)`
54
+
52
55
  Creates a new boolean array of the given size. All values are initialized to `false`.
53
56
 
54
57
  - **Parameters:**
55
58
  - `size` (number): The number of booleans the array should hold.
56
59
 
57
60
  ### `set(index, value)`
61
+
58
62
  Sets the boolean value at the specified index.
59
63
 
60
64
  - **Parameters:**
@@ -62,9 +66,11 @@ Sets the boolean value at the specified index.
62
66
  - `value` (boolean): The value to set (`true` or `false`).
63
67
 
64
68
  ### `get(index)`
69
+
65
70
  Gets the boolean value at the specified index.
66
71
 
67
72
  - **Parameters:**
73
+
68
74
  - `index` (number): The position in the array to retrieve the value.
69
75
 
70
76
  - **Returns:**
@@ -87,76 +93,84 @@ Our benchmark compares the performance of our Fast Boolean Array library against
87
93
  ## Performance Breakdown
88
94
 
89
95
  ### 1 Boolean
90
- | Test | Time (ms) | Memory (MB) |
91
- |--------------------------|-----------|-------------|
92
- | Set Vanilla Array | 0.00 | 0.00 |
93
- | Set Fast Boolean Array | 0.00 | 0.00 |
94
- | Get Vanilla Array | 0.00 | N/A |
95
- | Get Fast Boolean Array | 0.00 | N/A |
96
+
97
+ | Test | Time (ms) | Memory (MB) |
98
+ | ---------------------- | --------- | ----------- |
99
+ | Set Vanilla Array | 0.00 | 0.00 |
100
+ | Set Fast Boolean Array | 0.00 | 0.00 |
101
+ | Get Vanilla Array | 0.00 | N/A |
102
+ | Get Fast Boolean Array | 0.00 | N/A |
96
103
 
97
104
  **Observation:** At 1 boolean, both arrays remain equal in terms of performance and memory usage. Differences in performance are effectively immessurable, and one can assume practically identical.
98
105
 
99
106
  ### 100 Booleans
100
- | Test | Time (ms) | Memory (MB) |
101
- |--------------------------|-----------|-------------|
102
- | Set Vanilla Array | 0.00 | 0.00 |
103
- | Set Fast Boolean Array | 0.00 | 0.00 |
104
- | Get Vanilla Array | 0.00 | N/A |
105
- | Get Fast Boolean Array | 0.00 | N/A |
107
+
108
+ | Test | Time (ms) | Memory (MB) |
109
+ | ---------------------- | --------- | ----------- |
110
+ | Set Vanilla Array | 0.00 | 0.00 |
111
+ | Set Fast Boolean Array | 0.00 | 0.00 |
112
+ | Get Vanilla Array | 0.00 | N/A |
113
+ | Get Fast Boolean Array | 0.00 | N/A |
106
114
 
107
115
  **Observation:** At 100 booleans, both arrays remain equal in terms of performance and memory usage. Differences in performance are effectively immessurable, and one can assume practically identical.
108
116
 
109
117
  ### 1,000 Booleans
110
- | Test | Time (ms) | Memory (MB) |
111
- |--------------------------|-----------|-------------|
112
- | Set Vanilla Array | 0.01 | 0.00 |
113
- | Set Fast Boolean Array | 0.00 | 0.00 |
114
- | Get Vanilla Array | 0.00 | N/A |
115
- | Get Fast Boolean Array | 0.00 | N/A |
118
+
119
+ | Test | Time (ms) | Memory (MB) |
120
+ | ---------------------- | --------- | ----------- |
121
+ | Set Vanilla Array | 0.01 | 0.00 |
122
+ | Set Fast Boolean Array | 0.00 | 0.00 |
123
+ | Get Vanilla Array | 0.00 | N/A |
124
+ | Get Fast Boolean Array | 0.00 | N/A |
116
125
 
117
126
  **Observation:** At 1,000 booleans, the Fast Boolean Array is **10x** faster in set operations and uses **8x** less memory as expected. We have not yet been able to messure in actual bytes.
118
127
 
119
128
  ### 10,000 Booleans
120
- | Test | Time (ms) | Memory (MB) |
121
- |--------------------------|-----------|-------------|
122
- | Set Vanilla Array | 0.06 | 0.01 |
123
- | Set Fast Boolean Array | 0.02 | 0.00 |
124
- | Get Vanilla Array | 0.01 | N/A |
125
- | Get Fast Boolean Array | 0.01 | N/A |
129
+
130
+ | Test | Time (ms) | Memory (MB) |
131
+ | ---------------------- | --------- | ----------- |
132
+ | Set Vanilla Array | 0.06 | 0.01 |
133
+ | Set Fast Boolean Array | 0.02 | 0.00 |
134
+ | Get Vanilla Array | 0.01 | N/A |
135
+ | Get Fast Boolean Array | 0.01 | N/A |
126
136
 
127
137
  **Observation:** For 10,000 booleans, Fast Boolean Array is **3x** faster in set operations and uses **8x** less memory as expected.
128
138
 
129
139
  ### 100,000 Booleans
130
- | Test | Time (ms) | Memory (MB) |
131
- |--------------------------|-----------|-------------|
132
- | Set Vanilla Array | 1.37 | 0.10 |
133
- | Set Fast Boolean Array | 0.21 | 0.01 |
134
- | Get Vanilla Array | 0.05 | N/A |
135
- | Get Fast Boolean Array | 0.07 | N/A |
140
+
141
+ | Test | Time (ms) | Memory (MB) |
142
+ | ---------------------- | --------- | ----------- |
143
+ | Set Vanilla Array | 1.37 | 0.10 |
144
+ | Set Fast Boolean Array | 0.21 | 0.01 |
145
+ | Get Vanilla Array | 0.05 | N/A |
146
+ | Get Fast Boolean Array | 0.07 | N/A |
136
147
 
137
148
  **Observation:** At 100,000 booleans, Fast Boolean Array is approximately **6.5x** faster in set operations and uses **8x** less memory as expected.
138
149
 
139
150
  ### 1,000,000 Booleans
140
- | Test | Time (ms) | Memory (MB) |
141
- |--------------------------|-----------|-------------|
142
- | Set Vanilla Array | 19.62 | 0.95 |
143
- | Set Fast Boolean Array | 2.02 | 0.12 |
144
- | Get Vanilla Array | 0.48 | N/A |
145
- | Get Fast Boolean Array | 0.71 | N/A |
151
+
152
+ | Test | Time (ms) | Memory (MB) |
153
+ | ---------------------- | --------- | ----------- |
154
+ | Set Vanilla Array | 19.62 | 0.95 |
155
+ | Set Fast Boolean Array | 2.02 | 0.12 |
156
+ | Get Vanilla Array | 0.48 | N/A |
157
+ | Get Fast Boolean Array | 0.71 | N/A |
146
158
 
147
159
  **Observation:** For 1,000,000 booleans, Fast Boolean Array is nearly **10x** faster in set operations and uses **8x** less memory as expected.
148
160
 
149
161
  ### 10,000,000 Booleans
150
- | Test | Time (ms) | Memory (MB) |
151
- |--------------------------|-----------|-------------|
152
- | Set Vanilla Array | 259.10 | 9.54 |
153
- | Set Fast Boolean Array | 21.57 | 1.19 |
154
- | Get Vanilla Array | 4.90 | N/A |
155
- | Get Fast Boolean Array | 7.21 | N/A |
162
+
163
+ | Test | Time (ms) | Memory (MB) |
164
+ | ---------------------- | --------- | ----------- |
165
+ | Set Vanilla Array | 259.10 | 9.54 |
166
+ | Set Fast Boolean Array | 21.57 | 1.19 |
167
+ | Get Vanilla Array | 4.90 | N/A |
168
+ | Get Fast Boolean Array | 7.21 | N/A |
156
169
 
157
170
  **Observation:** At 10,000,000 booleans, Fast Boolean Array is about **12x** faster in set operations and uses nearly **8x** less memory as expected compared to Vanilla.
158
171
 
159
172
  ## Summary
173
+
160
174
  This updated benchmark confirms that the Fast Boolean Array library excels in scenarios involving large datasets, offering substantial improvements in set operation performance and memory efficiency. The sweet spot remains around 100,000 indexes, where the library achieves its most pronounced gains (6.5x faster and much lower memory usage) over Vanilla JavaScript arrays.
161
175
 
162
176
  ---
@@ -176,4 +190,3 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
176
190
  ## Acknowledgements
177
191
 
178
192
  Thank you to the open-source community for inspiration and support!
179
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-boolean-array",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "homepage": "https://github.com/UltraCakeBakery/FastBooleanArray",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.ts CHANGED
@@ -7,15 +7,30 @@ export default class FastBooleanArray {
7
7
  this.buffer = new Uint8Array(Math.ceil(size / 8)); // Allocate memory
8
8
  }
9
9
 
10
+ /**
11
+ * Set a boolean at a specific index
12
+ * @throws {RangeError} if `input` is less than `0` or more than the array `size`
13
+ */
10
14
  set(input: number, value: boolean) {
15
+ if (input < 0 || input >= this.size) {
16
+ throw new RangeError('Index out of bounds');
17
+ }
11
18
  if (value) {
12
19
  this.buffer[input >> 3] |= 1 << (input & 7); // Set bit
13
20
  } else {
14
21
  this.buffer[input >> 3] &= ~(1 << (input & 7)); // Clear bit
15
22
  }
23
+ return value;
16
24
  }
17
25
 
26
+ /**
27
+ * Set a boolean at a specific index
28
+ * @throws {RangeError} if `input` is less than `0` or more than the array `size`
29
+ */
18
30
  get(input: number) {
31
+ if (input < 0 || input >= this.size) {
32
+ throw new RangeError('Index out of bounds');
33
+ }
19
34
  return (this.buffer[input >> 3] & (1 << input % 8)) !== 0; // Check bit
20
35
  }
21
36
 
package/dist/index.cjs DELETED
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- default: () => FastBooleanArray
24
- });
25
- module.exports = __toCommonJS(src_exports);
26
- var FastBooleanArray = class {
27
- size;
28
- buffer;
29
- constructor(size) {
30
- this.size = size;
31
- this.buffer = new Uint8Array(Math.ceil(size / 8));
32
- }
33
- set(input, value) {
34
- if (value) {
35
- this.buffer[input >> 3] |= 1 << (input & 7);
36
- } else {
37
- this.buffer[input >> 3] &= ~(1 << (input & 7));
38
- }
39
- }
40
- get(input) {
41
- return (this.buffer[input >> 3] & 1 << input % 8) !== 0;
42
- }
43
- get length() {
44
- return this.size;
45
- }
46
- set length(value) {
47
- throw new Error("Setting the length on BooleanArray's is not supported");
48
- }
49
- };
50
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export default class FastBooleanArray {\r\n\tpublic size: number;\r\n\tprivate buffer: Uint8Array;\r\n\r\n\tconstructor(size: number) {\r\n\t\tthis.size = size;\r\n\t\tthis.buffer = new Uint8Array(Math.ceil(size / 8)); // Allocate memory\r\n\t}\r\n\r\n\tset(input: number, value: boolean) {\r\n\t\tif (value) {\r\n\t\t\tthis.buffer[input >> 3] |= 1 << (input & 7); // Set bit\r\n\t\t} else {\r\n\t\t\tthis.buffer[input >> 3] &= ~(1 << (input & 7)); // Clear bit\r\n\t\t}\r\n\t}\r\n\r\n\tget(input: number) {\r\n\t\treturn (this.buffer[input >> 3] & (1 << input % 8)) !== 0; // Check bit\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.size;\r\n\t}\r\n\r\n\tset length(value: number) {\r\n\t\tthrow new Error(\"Setting the length on BooleanArray's is not supported\");\r\n\t}\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAqB,mBAArB,MAAsC;AAAA,EAC9B;AAAA,EACC;AAAA,EAER,YAAY,MAAc;AACzB,SAAK,OAAO;AACZ,SAAK,SAAS,IAAI,WAAW,KAAK,KAAK,OAAO,CAAC,CAAC;AAAA,EACjD;AAAA,EAEA,IAAI,OAAe,OAAgB;AAClC,QAAI,OAAO;AACV,WAAK,OAAO,SAAS,CAAC,KAAK,MAAM,QAAQ;AAAA,IAC1C,OAAO;AACN,WAAK,OAAO,SAAS,CAAC,KAAK,EAAE,MAAM,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEA,IAAI,OAAe;AAClB,YAAQ,KAAK,OAAO,SAAS,CAAC,IAAK,KAAK,QAAQ,OAAQ;AAAA,EACzD;AAAA,EAEA,IAAI,SAAS;AACZ,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,IAAI,OAAO,OAAe;AACzB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACxE;AACD;","names":[]}
package/dist/index.d.cts DELETED
@@ -1,11 +0,0 @@
1
- declare class FastBooleanArray {
2
- size: number;
3
- private buffer;
4
- constructor(size: number);
5
- set(input: number, value: boolean): void;
6
- get(input: number): boolean;
7
- get length(): number;
8
- set length(value: number);
9
- }
10
-
11
- export { FastBooleanArray as default };
package/dist/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- declare class FastBooleanArray {
2
- size: number;
3
- private buffer;
4
- constructor(size: number);
5
- set(input: number, value: boolean): void;
6
- get(input: number): boolean;
7
- get length(): number;
8
- set length(value: number);
9
- }
10
-
11
- export { FastBooleanArray as default };
package/dist/index.js DELETED
@@ -1,29 +0,0 @@
1
- // src/index.ts
2
- var FastBooleanArray = class {
3
- size;
4
- buffer;
5
- constructor(size) {
6
- this.size = size;
7
- this.buffer = new Uint8Array(Math.ceil(size / 8));
8
- }
9
- set(input, value) {
10
- if (value) {
11
- this.buffer[input >> 3] |= 1 << (input & 7);
12
- } else {
13
- this.buffer[input >> 3] &= ~(1 << (input & 7));
14
- }
15
- }
16
- get(input) {
17
- return (this.buffer[input >> 3] & 1 << input % 8) !== 0;
18
- }
19
- get length() {
20
- return this.size;
21
- }
22
- set length(value) {
23
- throw new Error("Setting the length on BooleanArray's is not supported");
24
- }
25
- };
26
- export {
27
- FastBooleanArray as default
28
- };
29
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export default class FastBooleanArray {\r\n\tpublic size: number;\r\n\tprivate buffer: Uint8Array;\r\n\r\n\tconstructor(size: number) {\r\n\t\tthis.size = size;\r\n\t\tthis.buffer = new Uint8Array(Math.ceil(size / 8)); // Allocate memory\r\n\t}\r\n\r\n\tset(input: number, value: boolean) {\r\n\t\tif (value) {\r\n\t\t\tthis.buffer[input >> 3] |= 1 << (input & 7); // Set bit\r\n\t\t} else {\r\n\t\t\tthis.buffer[input >> 3] &= ~(1 << (input & 7)); // Clear bit\r\n\t\t}\r\n\t}\r\n\r\n\tget(input: number) {\r\n\t\treturn (this.buffer[input >> 3] & (1 << input % 8)) !== 0; // Check bit\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.size;\r\n\t}\r\n\r\n\tset length(value: number) {\r\n\t\tthrow new Error(\"Setting the length on BooleanArray's is not supported\");\r\n\t}\r\n}\r\n"],"mappings":";AAAA,IAAqB,mBAArB,MAAsC;AAAA,EAC9B;AAAA,EACC;AAAA,EAER,YAAY,MAAc;AACzB,SAAK,OAAO;AACZ,SAAK,SAAS,IAAI,WAAW,KAAK,KAAK,OAAO,CAAC,CAAC;AAAA,EACjD;AAAA,EAEA,IAAI,OAAe,OAAgB;AAClC,QAAI,OAAO;AACV,WAAK,OAAO,SAAS,CAAC,KAAK,MAAM,QAAQ;AAAA,IAC1C,OAAO;AACN,WAAK,OAAO,SAAS,CAAC,KAAK,EAAE,MAAM,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEA,IAAI,OAAe;AAClB,YAAQ,KAAK,OAAO,SAAS,CAAC,IAAK,KAAK,QAAQ,OAAQ;AAAA,EACzD;AAAA,EAEA,IAAI,SAAS;AACZ,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,IAAI,OAAO,OAAe;AACzB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACxE;AACD;","names":[]}