fast-boolean-array 1.4.0 → 1.4.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/README.md CHANGED
@@ -89,7 +89,7 @@ Gets the boolean value at the specified index.
89
89
 
90
90
  ---
91
91
 
92
- # Fast Boolean Array vs Vanilla JavaScript Array Performance
92
+ # Performance Breakdown
93
93
 
94
94
  Our benchmark compares the performance of our Fast Boolean Array library against Vanilla JavaScript arrays in terms of get and set operations across varying numbers of Booleans. The results below reflect an updated benchmark algorithm that performs 1,000 runs for each x amount of Booleans to better simulate real-world scenarios.
95
95
 
@@ -97,90 +97,113 @@ Our benchmark compares the performance of our Fast Boolean Array library against
97
97
 
98
98
  ### 1 Boolean
99
99
 
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 |
100
+ | Test | Time (ms) | Memory (Bytes) | Booleans |
101
+ | ---------------------- | ---------- | -------------- | -------- |
102
+ | Set Vanilla Array | 0.00236000 | 8 | 1 |
103
+ | Set Fast Boolean Array | 0.00423000 | 6 | 1 |
104
+ | Get Vanilla Array | 0.00053000 | N/A | 1 |
105
+ | Get Fast Boolean Array | 0.00291000 | N/A | 1 |
106
106
 
107
- **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.
107
+ **Observation:** As useless as having just 1 boolean stored in an array might be, For **1 boolean**, the **Fast Boolean Array** is **1.8x slower** for **Set** and **5.5x slower** for **Get** operations. Memory usage is nearly identical, with a small advantage for the **Fast Boolean Array** in terms of bytes.
108
+
109
+ ---
108
110
 
109
111
  ### 100 Booleans
110
112
 
111
- | Test | Time (ms) | Memory (MB) |
112
- | ---------------------- | --------- | ----------- |
113
- | Set Vanilla Array | 0.00 | 0.00 |
114
- | Set Fast Boolean Array | 0.00 | 0.00 |
115
- | Get Vanilla Array | 0.00 | N/A |
116
- | Get Fast Boolean Array | 0.00 | N/A |
113
+ | Test | Time (ms) | Memory (Bytes) | Booleans |
114
+ | ---------------------- | ---------- | -------------- | -------- |
115
+ | Set Vanilla Array | 0.00332000 | 107 | 100 |
116
+ | Set Fast Boolean Array | 0.00824000 | 18 | 100 |
117
+ | Get Vanilla Array | 0.00149000 | N/A | 100 |
118
+ | Get Fast Boolean Array | 0.00581000 | N/A | 100 |
117
119
 
118
- **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.
120
+ **Observation:** For **100 booleans**, **Fast Boolean Array** is **2.5x slower** in **Set** operations but **3.9x more memory efficient**. However, **Fast Boolean Array**'s' **Get** operation is **3.9x slower** . compared to the **Vanilla Array**.
121
+
122
+ ---
119
123
 
120
124
  ### 1,000 Booleans
121
125
 
122
- | Test | Time (ms) | Memory (MB) |
123
- | ---------------------- | --------- | ----------- |
124
- | Set Vanilla Array | 0.01 | 0.00 |
125
- | Set Fast Boolean Array | 0.00 | 0.00 |
126
- | Get Vanilla Array | 0.00 | N/A |
127
- | Get Fast Boolean Array | 0.00 | N/A |
126
+ | Test | Time (ms) | Memory (Bytes) | Booleans |
127
+ | ---------------------- | ---------- | -------------- | -------- |
128
+ | Set Vanilla Array | 0.09599000 | 1009 | 1000 |
129
+ | Set Fast Boolean Array | 0.04467000 | 130 | 1000 |
130
+ | Get Vanilla Array | 0.01261000 | N/A | 1000 |
131
+ | Get Fast Boolean Array | 0.05476000 | N/A | 1000 |
128
132
 
129
- **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.
133
+ **Observation:** For **1,000 booleans**, **Fast Boolean Array** is **2.1x faster** for **Set** operations and uses **7.7x less memory**. However, **Fast Boolean Array**'s' **Get** operation is **4.3x slower** . compared to the **Vanilla Array**.
134
+
135
+ ---
130
136
 
131
137
  ### 10,000 Booleans
132
138
 
133
- | Test | Time (ms) | Memory (MB) |
134
- | ---------------------- | --------- | ----------- |
135
- | Set Vanilla Array | 0.06 | 0.01 |
136
- | Set Fast Boolean Array | 0.02 | 0.00 |
137
- | Get Vanilla Array | 0.01 | N/A |
138
- | Get Fast Boolean Array | 0.01 | N/A |
139
+ | Test | Time (ms) | Memory (Bytes) | Booleans |
140
+ | ---------------------- | ---------- | -------------- | -------- |
141
+ | Set Vanilla Array | 0.30075000 | 10009 | 10000 |
142
+ | Set Fast Boolean Array | 0.04225000 | 1256 | 10000 |
143
+ | Get Vanilla Array | 0.06054000 | N/A | 10000 |
144
+ | Get Fast Boolean Array | 0.12325000 | N/A | 10000 |
145
+
146
+ **Observation:** For **10,000 booleans**, **Fast Boolean Array** is **7.1x faster** in **Set** operations and uses **8x less memory**. However, **Fast Boolean Array**'s' **Get** operation is **2x slower** . compared to the **Vanilla Array**.
139
147
 
140
- **Observation:** For 10,000 booleans, Fast Boolean Array is **3x** faster in set operations and uses **8x** less memory as expected.
148
+ ---
141
149
 
142
150
  ### 100,000 Booleans
143
151
 
144
- | Test | Time (ms) | Memory (MB) |
145
- | ---------------------- | --------- | ----------- |
146
- | Set Vanilla Array | 1.37 | 0.10 |
147
- | Set Fast Boolean Array | 0.21 | 0.01 |
148
- | Get Vanilla Array | 0.05 | N/A |
149
- | Get Fast Boolean Array | 0.07 | N/A |
152
+ | Test | Time (ms) | Memory (Bytes) | Booleans |
153
+ | ---------------------- | ---------- | -------------- | -------- |
154
+ | Set Vanilla Array | 1.67949000 | 100011 | 100000 |
155
+ | Set Fast Boolean Array | 0.15400000 | 12506 | 100000 |
156
+ | Get Vanilla Array | 0.04920000 | N/A | 100000 |
157
+ | Get Fast Boolean Array | 0.07523000 | N/A | 100000 |
158
+
159
+ **Observation:** For **100,000 booleans**, **Fast Boolean Array** is **10.9x faster** in **Set** operations and uses **8x less memory**. However, **Fast Boolean Array**'s' **Get** operation is **1.5x slower** .
150
160
 
151
- **Observation:** At 100,000 booleans, Fast Boolean Array is approximately **6.5x** faster in set operations and uses **8x** less memory as expected.
161
+ ---
152
162
 
153
163
  ### 1,000,000 Booleans
154
164
 
155
- | Test | Time (ms) | Memory (MB) |
156
- | ---------------------- | --------- | ----------- |
157
- | Set Vanilla Array | 19.62 | 0.95 |
158
- | Set Fast Boolean Array | 2.02 | 0.12 |
159
- | Get Vanilla Array | 0.48 | N/A |
160
- | Get Fast Boolean Array | 0.71 | N/A |
165
+ | Test | Time (ms) | Memory (Bytes) | Booleans |
166
+ | ---------------------- | ----------- | -------------- | -------- |
167
+ | Set Vanilla Array | 20.07889000 | 1000011 | 1000000 |
168
+ | Set Fast Boolean Array | 3.42817000 | 125007 | 1000000 |
169
+ | Get Vanilla Array | 0.49531000 | N/A | 1000000 |
170
+ | Get Fast Boolean Array | 0.74617000 | N/A | 1000000 |
171
+
172
+ **Observation:** For **1,000,000 booleans**, the **Fast Boolean Array** is **5.9x faster** for **Set** operations and uses **8x less memory**. However, **Fast Boolean Array**'s' **Get** operation is **1.5x slower** .
161
173
 
162
- **Observation:** For 1,000,000 booleans, Fast Boolean Array is nearly **10x** faster in set operations and uses **8x** less memory as expected.
174
+ ---
163
175
 
164
176
  ### 10,000,000 Booleans
165
177
 
166
- | Test | Time (ms) | Memory (MB) |
167
- | ---------------------- | --------- | ----------- |
168
- | Set Vanilla Array | 259.10 | 9.54 |
169
- | Set Fast Boolean Array | 21.57 | 1.19 |
170
- | Get Vanilla Array | 4.90 | N/A |
171
- | Get Fast Boolean Array | 7.21 | N/A |
178
+ | Test | Time (ms) | Memory (Bytes) | Booleans |
179
+ | ---------------------- | ------------ | -------------- | -------- |
180
+ | Set Vanilla Array | 266.65778000 | 10000013 | 10000000 |
181
+ | Set Fast Boolean Array | 35.53492000 | 1250007 | 10000000 |
182
+ | Get Vanilla Array | 4.90792000 | N/A | 10000000 |
183
+ | Get Fast Boolean Array | 7.57038000 | N/A | 10000000 |
172
184
 
173
- **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.
185
+ **Observation:** For **10,000,000 booleans**, **Fast Boolean Array** is **7.5x faster** for **Set** operations and uses **8x less memory**. However, **Fast Boolean Array**'s' **Get** operation is **1.5x slower** .
186
+
187
+ ---
188
+
189
+ ### Summary
190
+
191
+ - The **Fast Boolean Array** is significantly more efficient in terms of memory usage and **Set** operation speeds, particularly as the number of booleans increases.
192
+ - For example, at **10,000,000 booleans**, it is **7.5x faster** in **Set** operations and uses **8x less memory**.
193
+ - The **Get** operation, however, tends to be slower for the **Fast Boolean Array**, with it being up to **1.5x slower** compared to the **Vanilla Array** in larger datasets.
194
+ - If memory efficiency and **Set** performance are priorities, the **Fast Boolean Array** is clearly advantageous, but if **Get** performance is more important, the **Vanilla Array** may still offer better results for certain use cases.
195
+
196
+ ---
174
197
 
175
- ## Summary
198
+ # Why not use BigInt or larger array?
176
199
 
177
- 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.
200
+ Backwards compatibility with older version of NodeJS and browsers.
178
201
 
179
202
  ---
180
203
 
181
204
  ## Contributing
182
205
 
183
- Contributions are welcome! If you'd like to report a bug, suggest a feature, or submit a pull request, please visit the [GitHub repository](https://github.com/yourusername/fast-boolean-array).
206
+ Contributions are welcome! If you'd like to report a bug, suggest a feature, or submit a pull request, please visit the [GitHub repository](https://github.com/ultracakebakery/FastBooleanArray).
184
207
 
185
208
  ---
186
209
 
package/dist/index.cjs CHANGED
@@ -1,266 +1,2 @@
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 _FastBooleanArray {
27
- size;
28
- buffer;
29
- constructor(size) {
30
- if (!size) {
31
- throw new Error("FastBooleanArray must have a size greater than 0");
32
- }
33
- this.size = size;
34
- this.buffer = new Uint8Array(Math.ceil(size / 8));
35
- }
36
- /**
37
- * Sets a boolean value at the specified index.
38
- * @param {number} index - The index to set the boolean value at.
39
- * @param {number} value - The boolean value to set the `index`.
40
- * @returns {boolean} The boolean value that was set.
41
- */
42
- set(index, value) {
43
- if (value) {
44
- this.buffer[index >> 3] |= 1 << (index & 7);
45
- return true;
46
- } else {
47
- this.buffer[index >> 3] &= ~(1 << (index & 7));
48
- return false;
49
- }
50
- }
51
- /**
52
- * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
53
- * @param {number} index - The index to set the boolean value at.
54
- * @param {number} value - The boolean value to set the `index`.
55
- * @returns {boolean} The boolean value that was set.
56
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
57
- */
58
- setSafe(index, value) {
59
- if (index < 0 || index >= this.size) {
60
- throw new RangeError("Index out of bounds");
61
- }
62
- return this.set(index, value);
63
- }
64
- /**
65
- * Sets all bits to the specified boolean value.
66
- * @param {boolean} value - The boolean value to set all bits to.
67
- */
68
- setAll(value) {
69
- this.buffer.fill(value ? 255 : 0);
70
- }
71
- /**
72
- * Gets a boolean value at the specified index.
73
- * @param {number} index - The index to get the boolean value of.
74
- * @returns {boolean} The boolean value that was set.
75
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
76
- */
77
- get(index) {
78
- return !!(this.buffer[index >> 3] & 1 << index % 8);
79
- }
80
- /**
81
- * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
82
- * @param {number} index - The index to get the boolean value of.
83
- * @returns {boolean} The boolean value that was set.
84
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
85
- */
86
- getSafe(index) {
87
- if (index < 0 || index >= this.size) {
88
- throw new RangeError("Index out of bounds");
89
- }
90
- return this.get(index);
91
- }
92
- /**
93
- * Resizes the array to a new size, preserving existing data.
94
- * @param {number} newSize - The new size of the array.
95
- */
96
- resize(newSize) {
97
- const newBuffer = new Uint8Array(Math.ceil(newSize / 8));
98
- newBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));
99
- this.buffer = newBuffer;
100
- this.size = newSize;
101
- }
102
- get length() {
103
- return this.size;
104
- }
105
- /**
106
- * Compares this FastBooleanArray with another for equality.
107
- * @param {FastBooleanArray} other - The other FastBooleanArray to compare.
108
- * @returns {boolean} True if both arrays are equal, false otherwise.
109
- */
110
- equals(other) {
111
- if (this.size !== other.size) {
112
- return false;
113
- }
114
- return this.buffer.every((byte, i) => byte === other.buffer[i]);
115
- }
116
- /**
117
- * Makes the array iterable using `for...of`.
118
- */
119
- *[Symbol.iterator]() {
120
- for (let i = 0; i < this.size; i++) {
121
- yield this.get(i);
122
- }
123
- }
124
- /**
125
- * Converts to a standard JavaScript array.
126
- */
127
- toArray() {
128
- const arr = new Array(this.size);
129
- for (let i = 0; i < this.size; i++) {
130
- arr[i] = this.get(i);
131
- }
132
- return arr;
133
- }
134
- /**
135
- * Returns a proxy to the FastBooleanArray instance
136
- * With this you can access indexes like on an actual array.
137
- */
138
- accessLikeArray() {
139
- return new Proxy(this, {
140
- get: (target, prop) => {
141
- if (typeof prop === "string" && !isNaN(Number(prop))) {
142
- const index = Number(prop);
143
- return target.get(index);
144
- }
145
- return target[prop];
146
- },
147
- set: (target, prop, value) => {
148
- if (typeof prop === "string" && !isNaN(Number(prop))) {
149
- const index = Number(prop);
150
- return target.set(index, value);
151
- }
152
- return target[prop] = value;
153
- }
154
- });
155
- }
156
- /**
157
- * Applies a callback function to each element in the array.
158
- * @param {Function} callback - The function to execute on each element.
159
- */
160
- forEach(callback) {
161
- for (let i = 0; i < this.size; i++) {
162
- callback(this.get(i), i, this);
163
- }
164
- }
165
- /**
166
- * Creates a new array with the results of calling a provided function on every element.
167
- * @param {Function} callback - The function to execute on each element.
168
- */
169
- map(callback) {
170
- const result = new Array(this.size);
171
- for (let i = 0; i < this.size; i++) {
172
- result[i] = callback(this.get(i), i, this);
173
- }
174
- return result;
175
- }
176
- /**
177
- * Creates a new array with all elements that pass the test implemented by the provided function.
178
- * @param {Function} callback - The function to test each element.
179
- */
180
- filter(callback) {
181
- const result = [];
182
- for (let i = 0; i < this.size; i++) {
183
- const value = this.get(i);
184
- if (callback(value, i, this)) {
185
- result.push(value);
186
- }
187
- }
188
- return result;
189
- }
190
- /**
191
- * Tests whether at least one element in the array passes the test implemented by the provided function.
192
- * @param {Function} callback - The function to test each element.
193
- */
194
- some(callback) {
195
- for (let i = 0; i < this.size; i++) {
196
- if (callback(this.get(i), i, this)) {
197
- return true;
198
- }
199
- }
200
- return false;
201
- }
202
- /**
203
- * Tests whether all elements in the array pass the test implemented by the provided function.
204
- * @param {Function} callback - The function to test each element.
205
- */
206
- every(callback) {
207
- for (let i = 0; i < this.size; i++) {
208
- if (!callback(this.get(i), i, this)) {
209
- return false;
210
- }
211
- }
212
- return true;
213
- }
214
- /**
215
- * Reduces the array to a single value by applying a function to each element.
216
- * @param {Function} callback - The function to execute on each element.
217
- * @param {any} initialValue - The initial value for the accumulator.
218
- */
219
- reduce(callback, initialValue) {
220
- let accumulator = initialValue;
221
- for (let i = 0; i < this.size; i++) {
222
- accumulator = callback(accumulator, this.get(i), i, this);
223
- }
224
- return accumulator;
225
- }
226
- /**
227
- * Generates a string where every boolean is either a 0 or 1.
228
- */
229
- toString() {
230
- let result = ``;
231
- for (let i = 0; i < this.size; i++) {
232
- result += this.get(i) ? "1" : "0";
233
- }
234
- return result;
235
- }
236
- /**
237
- * Returns a FastBooleanArray from .toString() output
238
- */
239
- static fromString(value) {
240
- const array = new _FastBooleanArray(value.length);
241
- for (let i = 0; i < value.length; i++) {
242
- array.set(i, value[i] == "1");
243
- }
244
- return array;
245
- }
246
- /**
247
- * Returns a FastBooleanArray from a boolean array or number array
248
- */
249
- static fromArray(value) {
250
- const array = new _FastBooleanArray(value.length);
251
- for (let i = 0; i < value.length; i++) {
252
- array.set(i, !!value[i]);
253
- }
254
- return array;
255
- }
256
- /**
257
- * Returns a FastBooleanArray from a string, boolean array or number array
258
- */
259
- static from(value) {
260
- if (typeof value === "string") {
261
- return _FastBooleanArray.fromString(value);
262
- }
263
- return _FastBooleanArray.fromArray(value);
264
- }
265
- };
1
+ var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var l=(n,e)=>{for(var r in e)a(n,r,{get:e[r],enumerable:!0})},h=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of u(e))!f.call(n,s)&&s!==r&&a(n,s,{get:()=>e[s],enumerable:!(t=o(e,s))||t.enumerable});return n};var b=n=>h(a({},"__esModule",{value:!0}),n);var y={};l(y,{default:()=>i});module.exports=b(y);var i=class n{size;buffer;constructor(e){if(!e)throw new Error("FastBooleanArray must have a size greater than 0");this.size=e,this.buffer=new Uint8Array(Math.ceil(e/8))}set(e,r){return r?(this.buffer[e>>3]|=1<<(e&7),!0):(this.buffer[e>>3]&=~(1<<(e&7)),!1)}setSafe(e,r){if(e<0||e>=this.size)throw new RangeError("Index out of bounds");return this.set(e,r)}setAll(e){this.buffer.fill(e?255:0)}get(e){let r=e>>>3,t=e&7;return(this.buffer[r]&1<<t)!==0}getSafe(e){if(e<0||e>=this.size)throw new RangeError("Index out of bounds");return this.get(e)}resize(e){let r=new Uint8Array(Math.ceil(e/8));r.set(this.buffer.subarray(0,Math.min(this.buffer.length,r.length))),this.buffer=r,this.size=e}get length(){return this.size}equals(e){return this.size!==e.size?!1:this.buffer.every((r,t)=>r===e.buffer[t])}*[Symbol.iterator](){for(let e=0;e<this.size;e++)yield this.get(e)}toArray(){let e=new Array(this.size);for(let r=0;r<this.size;r++)e[r]=this.get(r);return e}accessLikeArray(){return new Proxy(this,{get:(e,r)=>{if(typeof r=="string"&&!isNaN(Number(r))){let t=Number(r);return e.get(t)}return e[r]},set:(e,r,t)=>{if(typeof r=="string"&&!isNaN(Number(r))){let s=Number(r);return e.set(s,t)}return e[r]=t}})}forEach(e){for(let r=0;r<this.size;r++)e(this.get(r),r,this)}map(e){let r=new Array(this.size);for(let t=0;t<this.size;t++)r[t]=e(this.get(t),t,this);return r}filter(e){let r=[];for(let t=0;t<this.size;t++){let s=this.get(t);e(s,t,this)&&r.push(s)}return r}some(e){for(let r=0;r<this.size;r++)if(e(this.get(r),r,this))return!0;return!1}every(e){for(let r=0;r<this.size;r++)if(!e(this.get(r),r,this))return!1;return!0}reduce(e,r){let t=r;for(let s=0;s<this.size;s++)t=e(t,this.get(s),s,this);return t}toString(){let e="";for(let r=0;r<this.size;r++)e+=this.get(r)?"1":"0";return e}static fromString(e){let r=new n(e.length);for(let t=0;t<e.length;t++)r.set(t,e[t]=="1");return r}static fromArray(e){let r=new n(e.length);for(let t=0;t<e.length;t++)r.set(t,!!e[t]);return r}static from(e){return typeof e=="string"?n.fromString(e):n.fromArray(e)}};
266
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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\tif (!size) {\r\n\t\t\tthrow new Error('FastBooleanArray must have a size greater than 0');\r\n\t\t}\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\t/**\r\n\t * Sets a boolean value at the specified index.\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t */\r\n\tset(index: number, value: boolean) {\r\n\t\tif (value) {\r\n\t\t\tthis.buffer[index >> 3] |= 1 << (index & 7); // Set bit\r\n\t\t\treturn true;\r\n\t\t} else {\r\n\t\t\tthis.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tsetSafe(index: number, value: boolean) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.set(index, value);\r\n\t}\r\n\r\n\t/**\r\n\t * Sets all bits to the specified boolean value.\r\n\t * @param {boolean} value - The boolean value to set all bits to.\r\n\t */\r\n\tsetAll(value: boolean) {\r\n\t\tthis.buffer.fill(value ? 0xff : 0x00);\r\n\t}\r\n\r\n\t/**\r\n\t * Gets a boolean value at the specified index.\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tget(index: number) {\r\n\t\treturn !!(this.buffer[index >> 3] & (1 << index % 8)); // Check bit\r\n\t}\r\n\r\n\t/**\r\n\t * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tgetSafe(index: number) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.get(index);\r\n\t}\r\n\r\n\t/**\r\n\t * Resizes the array to a new size, preserving existing data.\r\n\t * @param {number} newSize - The new size of the array.\r\n\t */\r\n\tresize(newSize: number) {\r\n\t\tconst newBuffer = new Uint8Array(Math.ceil(newSize / 8));\r\n\t\tnewBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));\r\n\t\tthis.buffer = newBuffer;\r\n\t\tthis.size = newSize;\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Compares this FastBooleanArray with another for equality.\r\n\t * @param {FastBooleanArray} other - The other FastBooleanArray to compare.\r\n\t * @returns {boolean} True if both arrays are equal, false otherwise.\r\n\t */\r\n\tequals(other: FastBooleanArray) {\r\n\t\tif (this.size !== other.size) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\treturn this.buffer.every((byte, i) => byte === other.buffer[i]);\r\n\t}\r\n\r\n\t/**\r\n\t * Makes the array iterable using `for...of`.\r\n\t */\r\n\t*[Symbol.iterator]() {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tyield this.get(i);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Converts to a standard JavaScript array.\r\n\t */\r\n\ttoArray() {\r\n\t\tconst arr = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tarr[i] = this.get(i);\r\n\t\t}\r\n\t\treturn arr;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a proxy to the FastBooleanArray instance\r\n\t * With this you can access indexes like on an actual array.\r\n\t */\r\n\taccessLikeArray() {\r\n\t\treturn new Proxy(this, {\r\n\t\t\tget: (target, prop) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.get(index);\r\n\t\t\t\t}\r\n\t\t\t\treturn target[prop as keyof FastBooleanArray];\r\n\t\t\t},\r\n\t\t\tset: (target, prop, value) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.set(index, value as never);\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn (target[prop as Exclude<keyof FastBooleanArray, 'length'>] = value);\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Applies a callback function to each element in the array.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tforEach(callback: (value: boolean, index: number, array: FastBooleanArray) => void) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tcallback(this.get(i), i, this);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with the results of calling a provided function on every element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tmap(callback: (value: boolean, index: number, array: FastBooleanArray) => never) {\r\n\t\tconst result = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult[i] = callback(this.get(i), i, this);\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with all elements that pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tfilter(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tconst result: boolean[] = [];\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tconst value = this.get(i);\r\n\t\t\tif (callback(value, i, this)) {\r\n\t\t\t\tresult.push(value);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether at least one element in the array passes the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tsome(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (callback(this.get(i), i, this)) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether all elements in the array pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tevery(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (!callback(this.get(i), i, this)) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\t/**\r\n\t * Reduces the array to a single value by applying a function to each element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t * @param {any} initialValue - The initial value for the accumulator.\r\n\t */\r\n\treduce<T>(\r\n\t\tcallback: (accumulator: T, value: boolean, index: number, array: FastBooleanArray) => T,\r\n\t\tinitialValue: T\r\n\t): T {\r\n\t\tlet accumulator = initialValue;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\taccumulator = callback(accumulator, this.get(i), i, this);\r\n\t\t}\r\n\t\treturn accumulator;\r\n\t}\r\n\r\n\t/**\r\n\t * Generates a string where every boolean is either a 0 or 1.\r\n\t */\r\n\ttoString() {\r\n\t\tlet result = ``;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult += this.get(i) ? '1' : '0';\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from .toString() output\r\n\t */\r\n\tstatic fromString(value: string) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, value[i] == '1');\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a boolean array or number array\r\n\t */\r\n\tstatic fromArray(value: boolean[] | number[]) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, !!value[i]);\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a string, boolean array or number array\r\n\t */\r\n\tstatic from(value: string | boolean[] | number[]) {\r\n\t\tif (typeof value === 'string') {\r\n\t\t\treturn FastBooleanArray.fromString(value);\r\n\t\t}\r\n\r\n\t\treturn FastBooleanArray.fromArray(value);\r\n\t}\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAqB,mBAArB,MAAqB,kBAAiB;AAAA,EAC9B;AAAA,EACC;AAAA,EAER,YAAY,MAAc;AACzB,QAAI,CAAC,MAAM;AACV,YAAM,IAAI,MAAM,kDAAkD;AAAA,IACnE;AACA,SAAK,OAAO;AACZ,SAAK,SAAS,IAAI,WAAW,KAAK,KAAK,OAAO,CAAC,CAAC;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,OAAe,OAAgB;AAClC,QAAI,OAAO;AACV,WAAK,OAAO,SAAS,CAAC,KAAK,MAAM,QAAQ;AACzC,aAAO;AAAA,IACR,OAAO;AACN,WAAK,OAAO,SAAS,CAAC,KAAK,EAAE,MAAM,QAAQ;AAC3C,aAAO;AAAA,IACR;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,QAAQ,OAAe,OAAgB;AACtC,QAAI,QAAQ,KAAK,SAAS,KAAK,MAAM;AACpC,YAAM,IAAI,WAAW,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AKA,OAAO,UAAU,OAA6B;AAC7C,UAAM,QAAQ,IAAI,kBAAiB,MAAM,MAAM;AAC/C,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,YAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AAAA,IACxB;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,KAAK,OAAsC;AACjD,QAAI,OAAO,UAAU,UAAU;AAC9B,aAAO,kBAAiB,WAAW,KAAK;AAAA,IACzC;AAEA,WAAO,kBAAiB,UAAU,KAAK;AAAA,EACxC;AACD;","names":[]}
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\tif (!size) {\r\n\t\t\tthrow new Error('FastBooleanArray must have a size greater than 0');\r\n\t\t}\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\t/**\r\n\t * Sets a boolean value at the specified index.\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t */\r\n\tset(index: number, value: boolean) {\r\n\t\tif (value) {\r\n\t\t\tthis.buffer[index >> 3] |= 1 << (index & 7); // Set bit\r\n\t\t\treturn true;\r\n\t\t} else {\r\n\t\t\tthis.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tsetSafe(index: number, value: boolean) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.set(index, value);\r\n\t}\r\n\r\n\t/**\r\n\t * Sets all bits to the specified boolean value.\r\n\t * @param {boolean} value - The boolean value to set all bits to.\r\n\t */\r\n\tsetAll(value: boolean) {\r\n\t\tthis.buffer.fill(value ? 0xff : 0x00);\r\n\t}\r\n\r\n\t/**\r\n\t * Gets a boolean value at the specified index.\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tget(index: number) {\r\n\t\tconst byteIndex = index >>> 3; // index divided by 8 (shifted)\r\n\t\tconst bitIndex = index & 7; // index modulo 8 (masking)\r\n\t\treturn (this.buffer[byteIndex] & (1 << bitIndex)) !== 0; // Direct comparison is faster than double negation !!\r\n\t}\r\n\r\n\t/**\r\n\t * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tgetSafe(index: number) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.get(index);\r\n\t}\r\n\r\n\t/**\r\n\t * Resizes the array to a new size, preserving existing data.\r\n\t * @param {number} newSize - The new size of the array.\r\n\t */\r\n\tresize(newSize: number) {\r\n\t\tconst newBuffer = new Uint8Array(Math.ceil(newSize / 8));\r\n\t\tnewBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));\r\n\t\tthis.buffer = newBuffer;\r\n\t\tthis.size = newSize;\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Compares this FastBooleanArray with another for equality.\r\n\t * @param {FastBooleanArray} other - The other FastBooleanArray to compare.\r\n\t * @returns {boolean} True if both arrays are equal, false otherwise.\r\n\t */\r\n\tequals(other: FastBooleanArray) {\r\n\t\tif (this.size !== other.size) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\treturn this.buffer.every((byte, i) => byte === other.buffer[i]);\r\n\t}\r\n\r\n\t/**\r\n\t * Makes the array iterable using `for...of`.\r\n\t */\r\n\t*[Symbol.iterator]() {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tyield this.get(i);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Converts to a standard JavaScript array.\r\n\t */\r\n\ttoArray() {\r\n\t\tconst arr = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tarr[i] = this.get(i);\r\n\t\t}\r\n\t\treturn arr;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a proxy to the FastBooleanArray instance\r\n\t * With this you can access indexes like on an actual array.\r\n\t */\r\n\taccessLikeArray() {\r\n\t\treturn new Proxy(this, {\r\n\t\t\tget: (target, prop) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.get(index);\r\n\t\t\t\t}\r\n\t\t\t\treturn target[prop as keyof FastBooleanArray];\r\n\t\t\t},\r\n\t\t\tset: (target, prop, value) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.set(index, value as never);\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn (target[prop as Exclude<keyof FastBooleanArray, 'length'>] = value);\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Applies a callback function to each element in the array.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tforEach(callback: (value: boolean, index: number, array: FastBooleanArray) => void) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tcallback(this.get(i), i, this);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with the results of calling a provided function on every element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tmap(callback: (value: boolean, index: number, array: FastBooleanArray) => never) {\r\n\t\tconst result = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult[i] = callback(this.get(i), i, this);\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with all elements that pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tfilter(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tconst result: boolean[] = [];\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tconst value = this.get(i);\r\n\t\t\tif (callback(value, i, this)) {\r\n\t\t\t\tresult.push(value);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether at least one element in the array passes the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tsome(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (callback(this.get(i), i, this)) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether all elements in the array pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tevery(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (!callback(this.get(i), i, this)) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\t/**\r\n\t * Reduces the array to a single value by applying a function to each element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t * @param {any} initialValue - The initial value for the accumulator.\r\n\t */\r\n\treduce<T>(\r\n\t\tcallback: (accumulator: T, value: boolean, index: number, array: FastBooleanArray) => T,\r\n\t\tinitialValue: T\r\n\t): T {\r\n\t\tlet accumulator = initialValue;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\taccumulator = callback(accumulator, this.get(i), i, this);\r\n\t\t}\r\n\t\treturn accumulator;\r\n\t}\r\n\r\n\t/**\r\n\t * Generates a string where every boolean is either a 0 or 1.\r\n\t */\r\n\ttoString() {\r\n\t\tlet result = ``;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult += this.get(i) ? '1' : '0';\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from .toString() output\r\n\t */\r\n\tstatic fromString(value: string) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, value[i] == '1');\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a boolean array or number array\r\n\t */\r\n\tstatic fromArray(value: boolean[] | number[]) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, !!value[i]);\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a string, boolean array or number array\r\n\t */\r\n\tstatic from(value: string | boolean[] | number[]) {\r\n\t\tif (typeof value === 'string') {\r\n\t\t\treturn FastBooleanArray.fromString(value);\r\n\t\t}\r\n\r\n\t\treturn FastBooleanArray.fromArray(value);\r\n\t}\r\n}\r\n"],"mappings":"4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAqBE,EAArB,M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ports","__export","FastBooleanArray","__toCommonJS","_FastBooleanArray","size","index","value","byteIndex","bitIndex","newSize","newBuffer","other","byte","i","arr","target","prop","callback","result","initialValue","accumulator","array"]}
package/dist/index.js CHANGED
@@ -1,245 +1,2 @@
1
- // src/index.ts
2
- var FastBooleanArray = class _FastBooleanArray {
3
- size;
4
- buffer;
5
- constructor(size) {
6
- if (!size) {
7
- throw new Error("FastBooleanArray must have a size greater than 0");
8
- }
9
- this.size = size;
10
- this.buffer = new Uint8Array(Math.ceil(size / 8));
11
- }
12
- /**
13
- * Sets a boolean value at the specified index.
14
- * @param {number} index - The index to set the boolean value at.
15
- * @param {number} value - The boolean value to set the `index`.
16
- * @returns {boolean} The boolean value that was set.
17
- */
18
- set(index, value) {
19
- if (value) {
20
- this.buffer[index >> 3] |= 1 << (index & 7);
21
- return true;
22
- } else {
23
- this.buffer[index >> 3] &= ~(1 << (index & 7));
24
- return false;
25
- }
26
- }
27
- /**
28
- * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
29
- * @param {number} index - The index to set the boolean value at.
30
- * @param {number} value - The boolean value to set the `index`.
31
- * @returns {boolean} The boolean value that was set.
32
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
33
- */
34
- setSafe(index, value) {
35
- if (index < 0 || index >= this.size) {
36
- throw new RangeError("Index out of bounds");
37
- }
38
- return this.set(index, value);
39
- }
40
- /**
41
- * Sets all bits to the specified boolean value.
42
- * @param {boolean} value - The boolean value to set all bits to.
43
- */
44
- setAll(value) {
45
- this.buffer.fill(value ? 255 : 0);
46
- }
47
- /**
48
- * Gets a boolean value at the specified index.
49
- * @param {number} index - The index to get the boolean value of.
50
- * @returns {boolean} The boolean value that was set.
51
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
52
- */
53
- get(index) {
54
- return !!(this.buffer[index >> 3] & 1 << index % 8);
55
- }
56
- /**
57
- * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
58
- * @param {number} index - The index to get the boolean value of.
59
- * @returns {boolean} The boolean value that was set.
60
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
61
- */
62
- getSafe(index) {
63
- if (index < 0 || index >= this.size) {
64
- throw new RangeError("Index out of bounds");
65
- }
66
- return this.get(index);
67
- }
68
- /**
69
- * Resizes the array to a new size, preserving existing data.
70
- * @param {number} newSize - The new size of the array.
71
- */
72
- resize(newSize) {
73
- const newBuffer = new Uint8Array(Math.ceil(newSize / 8));
74
- newBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));
75
- this.buffer = newBuffer;
76
- this.size = newSize;
77
- }
78
- get length() {
79
- return this.size;
80
- }
81
- /**
82
- * Compares this FastBooleanArray with another for equality.
83
- * @param {FastBooleanArray} other - The other FastBooleanArray to compare.
84
- * @returns {boolean} True if both arrays are equal, false otherwise.
85
- */
86
- equals(other) {
87
- if (this.size !== other.size) {
88
- return false;
89
- }
90
- return this.buffer.every((byte, i) => byte === other.buffer[i]);
91
- }
92
- /**
93
- * Makes the array iterable using `for...of`.
94
- */
95
- *[Symbol.iterator]() {
96
- for (let i = 0; i < this.size; i++) {
97
- yield this.get(i);
98
- }
99
- }
100
- /**
101
- * Converts to a standard JavaScript array.
102
- */
103
- toArray() {
104
- const arr = new Array(this.size);
105
- for (let i = 0; i < this.size; i++) {
106
- arr[i] = this.get(i);
107
- }
108
- return arr;
109
- }
110
- /**
111
- * Returns a proxy to the FastBooleanArray instance
112
- * With this you can access indexes like on an actual array.
113
- */
114
- accessLikeArray() {
115
- return new Proxy(this, {
116
- get: (target, prop) => {
117
- if (typeof prop === "string" && !isNaN(Number(prop))) {
118
- const index = Number(prop);
119
- return target.get(index);
120
- }
121
- return target[prop];
122
- },
123
- set: (target, prop, value) => {
124
- if (typeof prop === "string" && !isNaN(Number(prop))) {
125
- const index = Number(prop);
126
- return target.set(index, value);
127
- }
128
- return target[prop] = value;
129
- }
130
- });
131
- }
132
- /**
133
- * Applies a callback function to each element in the array.
134
- * @param {Function} callback - The function to execute on each element.
135
- */
136
- forEach(callback) {
137
- for (let i = 0; i < this.size; i++) {
138
- callback(this.get(i), i, this);
139
- }
140
- }
141
- /**
142
- * Creates a new array with the results of calling a provided function on every element.
143
- * @param {Function} callback - The function to execute on each element.
144
- */
145
- map(callback) {
146
- const result = new Array(this.size);
147
- for (let i = 0; i < this.size; i++) {
148
- result[i] = callback(this.get(i), i, this);
149
- }
150
- return result;
151
- }
152
- /**
153
- * Creates a new array with all elements that pass the test implemented by the provided function.
154
- * @param {Function} callback - The function to test each element.
155
- */
156
- filter(callback) {
157
- const result = [];
158
- for (let i = 0; i < this.size; i++) {
159
- const value = this.get(i);
160
- if (callback(value, i, this)) {
161
- result.push(value);
162
- }
163
- }
164
- return result;
165
- }
166
- /**
167
- * Tests whether at least one element in the array passes the test implemented by the provided function.
168
- * @param {Function} callback - The function to test each element.
169
- */
170
- some(callback) {
171
- for (let i = 0; i < this.size; i++) {
172
- if (callback(this.get(i), i, this)) {
173
- return true;
174
- }
175
- }
176
- return false;
177
- }
178
- /**
179
- * Tests whether all elements in the array pass the test implemented by the provided function.
180
- * @param {Function} callback - The function to test each element.
181
- */
182
- every(callback) {
183
- for (let i = 0; i < this.size; i++) {
184
- if (!callback(this.get(i), i, this)) {
185
- return false;
186
- }
187
- }
188
- return true;
189
- }
190
- /**
191
- * Reduces the array to a single value by applying a function to each element.
192
- * @param {Function} callback - The function to execute on each element.
193
- * @param {any} initialValue - The initial value for the accumulator.
194
- */
195
- reduce(callback, initialValue) {
196
- let accumulator = initialValue;
197
- for (let i = 0; i < this.size; i++) {
198
- accumulator = callback(accumulator, this.get(i), i, this);
199
- }
200
- return accumulator;
201
- }
202
- /**
203
- * Generates a string where every boolean is either a 0 or 1.
204
- */
205
- toString() {
206
- let result = ``;
207
- for (let i = 0; i < this.size; i++) {
208
- result += this.get(i) ? "1" : "0";
209
- }
210
- return result;
211
- }
212
- /**
213
- * Returns a FastBooleanArray from .toString() output
214
- */
215
- static fromString(value) {
216
- const array = new _FastBooleanArray(value.length);
217
- for (let i = 0; i < value.length; i++) {
218
- array.set(i, value[i] == "1");
219
- }
220
- return array;
221
- }
222
- /**
223
- * Returns a FastBooleanArray from a boolean array or number array
224
- */
225
- static fromArray(value) {
226
- const array = new _FastBooleanArray(value.length);
227
- for (let i = 0; i < value.length; i++) {
228
- array.set(i, !!value[i]);
229
- }
230
- return array;
231
- }
232
- /**
233
- * Returns a FastBooleanArray from a string, boolean array or number array
234
- */
235
- static from(value) {
236
- if (typeof value === "string") {
237
- return _FastBooleanArray.fromString(value);
238
- }
239
- return _FastBooleanArray.fromArray(value);
240
- }
241
- };
242
- export {
243
- FastBooleanArray as default
244
- };
1
+ var i=class n{size;buffer;constructor(e){if(!e)throw new Error("FastBooleanArray must have a size greater than 0");this.size=e,this.buffer=new Uint8Array(Math.ceil(e/8))}set(e,r){return r?(this.buffer[e>>3]|=1<<(e&7),!0):(this.buffer[e>>3]&=~(1<<(e&7)),!1)}setSafe(e,r){if(e<0||e>=this.size)throw new RangeError("Index out of bounds");return this.set(e,r)}setAll(e){this.buffer.fill(e?255:0)}get(e){let r=e>>>3,t=e&7;return(this.buffer[r]&1<<t)!==0}getSafe(e){if(e<0||e>=this.size)throw new RangeError("Index out of bounds");return this.get(e)}resize(e){let r=new Uint8Array(Math.ceil(e/8));r.set(this.buffer.subarray(0,Math.min(this.buffer.length,r.length))),this.buffer=r,this.size=e}get length(){return this.size}equals(e){return this.size!==e.size?!1:this.buffer.every((r,t)=>r===e.buffer[t])}*[Symbol.iterator](){for(let e=0;e<this.size;e++)yield this.get(e)}toArray(){let e=new Array(this.size);for(let r=0;r<this.size;r++)e[r]=this.get(r);return e}accessLikeArray(){return new Proxy(this,{get:(e,r)=>{if(typeof r=="string"&&!isNaN(Number(r))){let t=Number(r);return e.get(t)}return e[r]},set:(e,r,t)=>{if(typeof r=="string"&&!isNaN(Number(r))){let s=Number(r);return e.set(s,t)}return e[r]=t}})}forEach(e){for(let r=0;r<this.size;r++)e(this.get(r),r,this)}map(e){let r=new Array(this.size);for(let t=0;t<this.size;t++)r[t]=e(this.get(t),t,this);return r}filter(e){let r=[];for(let t=0;t<this.size;t++){let s=this.get(t);e(s,t,this)&&r.push(s)}return r}some(e){for(let r=0;r<this.size;r++)if(e(this.get(r),r,this))return!0;return!1}every(e){for(let r=0;r<this.size;r++)if(!e(this.get(r),r,this))return!1;return!0}reduce(e,r){let t=r;for(let s=0;s<this.size;s++)t=e(t,this.get(s),s,this);return t}toString(){let e="";for(let r=0;r<this.size;r++)e+=this.get(r)?"1":"0";return e}static fromString(e){let r=new n(e.length);for(let t=0;t<e.length;t++)r.set(t,e[t]=="1");return r}static fromArray(e){let r=new n(e.length);for(let t=0;t<e.length;t++)r.set(t,!!e[t]);return r}static from(e){return typeof e=="string"?n.fromString(e):n.fromArray(e)}};export{i as default};
245
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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\tif (!size) {\r\n\t\t\tthrow new Error('FastBooleanArray must have a size greater than 0');\r\n\t\t}\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\t/**\r\n\t * Sets a boolean value at the specified index.\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t */\r\n\tset(index: number, value: boolean) {\r\n\t\tif (value) {\r\n\t\t\tthis.buffer[index >> 3] |= 1 << (index & 7); // Set bit\r\n\t\t\treturn true;\r\n\t\t} else {\r\n\t\t\tthis.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tsetSafe(index: number, value: boolean) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.set(index, value);\r\n\t}\r\n\r\n\t/**\r\n\t * Sets all bits to the specified boolean value.\r\n\t * @param {boolean} value - The boolean value to set all bits to.\r\n\t */\r\n\tsetAll(value: boolean) {\r\n\t\tthis.buffer.fill(value ? 0xff : 0x00);\r\n\t}\r\n\r\n\t/**\r\n\t * Gets a boolean value at the specified index.\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tget(index: number) {\r\n\t\treturn !!(this.buffer[index >> 3] & (1 << index % 8)); // Check bit\r\n\t}\r\n\r\n\t/**\r\n\t * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tgetSafe(index: number) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.get(index);\r\n\t}\r\n\r\n\t/**\r\n\t * Resizes the array to a new size, preserving existing data.\r\n\t * @param {number} newSize - The new size of the array.\r\n\t */\r\n\tresize(newSize: number) {\r\n\t\tconst newBuffer = new Uint8Array(Math.ceil(newSize / 8));\r\n\t\tnewBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));\r\n\t\tthis.buffer = newBuffer;\r\n\t\tthis.size = newSize;\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Compares this FastBooleanArray with another for equality.\r\n\t * @param {FastBooleanArray} other - The other FastBooleanArray to compare.\r\n\t * @returns {boolean} True if both arrays are equal, false otherwise.\r\n\t */\r\n\tequals(other: FastBooleanArray) {\r\n\t\tif (this.size !== other.size) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\treturn this.buffer.every((byte, i) => byte === other.buffer[i]);\r\n\t}\r\n\r\n\t/**\r\n\t * Makes the array iterable using `for...of`.\r\n\t */\r\n\t*[Symbol.iterator]() {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tyield this.get(i);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Converts to a standard JavaScript array.\r\n\t */\r\n\ttoArray() {\r\n\t\tconst arr = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tarr[i] = this.get(i);\r\n\t\t}\r\n\t\treturn arr;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a proxy to the FastBooleanArray instance\r\n\t * With this you can access indexes like on an actual array.\r\n\t */\r\n\taccessLikeArray() {\r\n\t\treturn new Proxy(this, {\r\n\t\t\tget: (target, prop) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.get(index);\r\n\t\t\t\t}\r\n\t\t\t\treturn target[prop as keyof FastBooleanArray];\r\n\t\t\t},\r\n\t\t\tset: (target, prop, value) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.set(index, value as never);\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn (target[prop as Exclude<keyof FastBooleanArray, 'length'>] = value);\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Applies a callback function to each element in the array.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tforEach(callback: (value: boolean, index: number, array: FastBooleanArray) => void) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tcallback(this.get(i), i, this);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with the results of calling a provided function on every element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tmap(callback: (value: boolean, index: number, array: FastBooleanArray) => never) {\r\n\t\tconst result = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult[i] = callback(this.get(i), i, this);\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with all elements that pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tfilter(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tconst result: boolean[] = [];\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tconst value = this.get(i);\r\n\t\t\tif (callback(value, i, this)) {\r\n\t\t\t\tresult.push(value);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether at least one element in the array passes the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tsome(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (callback(this.get(i), i, this)) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether all elements in the array pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tevery(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (!callback(this.get(i), i, this)) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\t/**\r\n\t * Reduces the array to a single value by applying a function to each element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t * @param {any} initialValue - The initial value for the accumulator.\r\n\t */\r\n\treduce<T>(\r\n\t\tcallback: (accumulator: T, value: boolean, index: number, array: FastBooleanArray) => T,\r\n\t\tinitialValue: T\r\n\t): T {\r\n\t\tlet accumulator = initialValue;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\taccumulator = callback(accumulator, this.get(i), i, this);\r\n\t\t}\r\n\t\treturn accumulator;\r\n\t}\r\n\r\n\t/**\r\n\t * Generates a string where every boolean is either a 0 or 1.\r\n\t */\r\n\ttoString() {\r\n\t\tlet result = ``;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult += this.get(i) ? '1' : '0';\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from .toString() output\r\n\t */\r\n\tstatic fromString(value: string) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, value[i] == '1');\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a boolean array or number array\r\n\t */\r\n\tstatic fromArray(value: boolean[] | number[]) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, !!value[i]);\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a string, boolean array or number array\r\n\t */\r\n\tstatic from(value: string | boolean[] | number[]) {\r\n\t\tif (typeof value === 'string') {\r\n\t\t\treturn FastBooleanArray.fromString(value);\r\n\t\t}\r\n\r\n\t\treturn FastBooleanArray.fromArray(value);\r\n\t}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ACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OACC,UACA,cACI;AACJ,QAAI,cAAc;AAClB,aAAS,IAAI,GAAG,IAAI,KAAK,MAAM,KAAK;AACnC,oBAAc,SAAS,aAAa,KAAK,IAAI,CAAC,GAAG,GAAG,IAAI;AAAA,IACzD;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACV,QAAI,SAAS;AACb,aAAS,IAAI,GAAG,IAAI,KAAK,MAAM,KAAK;AACnC,gBAAU,KAAK,IAAI,CAAC,IAAI,MAAM;AAAA,IAC/B;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,WAAW,OAAe;AAChC,UAAM,QAAQ,IAAI,kBAAiB,MAAM,MAAM;AAC/C,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,YAAM,IAAI,GAAG,MAAM,CAAC,KAAK,GAAG;AAAA,IAC7B;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,UAAU,OAA6B;AAC7C,UAAM,QAAQ,IAAI,kBAAiB,MAAM,MAAM;AAC/C,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,YAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AAAA,IACxB;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,KAAK,OAAsC;AACjD,QAAI,OAAO,UAAU,UAAU;AAC9B,aAAO,kBAAiB,WAAW,KAAK;AAAA,IACzC;AAEA,WAAO,kBAAiB,UAAU,KAAK;AAAA,EACxC;AACD;","names":[]}
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\tif (!size) {\r\n\t\t\tthrow new Error('FastBooleanArray must have a size greater than 0');\r\n\t\t}\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\t/**\r\n\t * Sets a boolean value at the specified index.\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t */\r\n\tset(index: number, value: boolean) {\r\n\t\tif (value) {\r\n\t\t\tthis.buffer[index >> 3] |= 1 << (index & 7); // Set bit\r\n\t\t\treturn true;\r\n\t\t} else {\r\n\t\t\tthis.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to set the boolean value at.\r\n\t * @param {number} value - The boolean value to set the `index`.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tsetSafe(index: number, value: boolean) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.set(index, value);\r\n\t}\r\n\r\n\t/**\r\n\t * Sets all bits to the specified boolean value.\r\n\t * @param {boolean} value - The boolean value to set all bits to.\r\n\t */\r\n\tsetAll(value: boolean) {\r\n\t\tthis.buffer.fill(value ? 0xff : 0x00);\r\n\t}\r\n\r\n\t/**\r\n\t * Gets a boolean value at the specified index.\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tget(index: number) {\r\n\t\tconst byteIndex = index >>> 3; // index divided by 8 (shifted)\r\n\t\tconst bitIndex = index & 7; // index modulo 8 (masking)\r\n\t\treturn (this.buffer[byteIndex] & (1 << bitIndex)) !== 0; // Direct comparison is faster than double negation !!\r\n\t}\r\n\r\n\t/**\r\n\t * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t * @param {number} index - The index to get the boolean value of.\r\n\t * @returns {boolean} The boolean value that was set.\r\n\t * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n\t */\r\n\tgetSafe(index: number) {\r\n\t\tif (index < 0 || index >= this.size) {\r\n\t\t\tthrow new RangeError('Index out of bounds');\r\n\t\t}\r\n\t\treturn this.get(index);\r\n\t}\r\n\r\n\t/**\r\n\t * Resizes the array to a new size, preserving existing data.\r\n\t * @param {number} newSize - The new size of the array.\r\n\t */\r\n\tresize(newSize: number) {\r\n\t\tconst newBuffer = new Uint8Array(Math.ceil(newSize / 8));\r\n\t\tnewBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));\r\n\t\tthis.buffer = newBuffer;\r\n\t\tthis.size = newSize;\r\n\t}\r\n\r\n\tget length() {\r\n\t\treturn this.size;\r\n\t}\r\n\r\n\t/**\r\n\t * Compares this FastBooleanArray with another for equality.\r\n\t * @param {FastBooleanArray} other - The other FastBooleanArray to compare.\r\n\t * @returns {boolean} True if both arrays are equal, false otherwise.\r\n\t */\r\n\tequals(other: FastBooleanArray) {\r\n\t\tif (this.size !== other.size) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\treturn this.buffer.every((byte, i) => byte === other.buffer[i]);\r\n\t}\r\n\r\n\t/**\r\n\t * Makes the array iterable using `for...of`.\r\n\t */\r\n\t*[Symbol.iterator]() {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tyield this.get(i);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Converts to a standard JavaScript array.\r\n\t */\r\n\ttoArray() {\r\n\t\tconst arr = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tarr[i] = this.get(i);\r\n\t\t}\r\n\t\treturn arr;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a proxy to the FastBooleanArray instance\r\n\t * With this you can access indexes like on an actual array.\r\n\t */\r\n\taccessLikeArray() {\r\n\t\treturn new Proxy(this, {\r\n\t\t\tget: (target, prop) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.get(index);\r\n\t\t\t\t}\r\n\t\t\t\treturn target[prop as keyof FastBooleanArray];\r\n\t\t\t},\r\n\t\t\tset: (target, prop, value) => {\r\n\t\t\t\tif (typeof prop === 'string' && !isNaN(Number(prop))) {\r\n\t\t\t\t\tconst index = Number(prop);\r\n\t\t\t\t\treturn target.set(index, value as never);\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn (target[prop as Exclude<keyof FastBooleanArray, 'length'>] = value);\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Applies a callback function to each element in the array.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tforEach(callback: (value: boolean, index: number, array: FastBooleanArray) => void) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tcallback(this.get(i), i, this);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with the results of calling a provided function on every element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t */\r\n\tmap(callback: (value: boolean, index: number, array: FastBooleanArray) => never) {\r\n\t\tconst result = new Array(this.size);\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult[i] = callback(this.get(i), i, this);\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a new array with all elements that pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tfilter(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tconst result: boolean[] = [];\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tconst value = this.get(i);\r\n\t\t\tif (callback(value, i, this)) {\r\n\t\t\t\tresult.push(value);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether at least one element in the array passes the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tsome(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (callback(this.get(i), i, this)) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Tests whether all elements in the array pass the test implemented by the provided function.\r\n\t * @param {Function} callback - The function to test each element.\r\n\t */\r\n\tevery(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean) {\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tif (!callback(this.get(i), i, this)) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\t/**\r\n\t * Reduces the array to a single value by applying a function to each element.\r\n\t * @param {Function} callback - The function to execute on each element.\r\n\t * @param {any} initialValue - The initial value for the accumulator.\r\n\t */\r\n\treduce<T>(\r\n\t\tcallback: (accumulator: T, value: boolean, index: number, array: FastBooleanArray) => T,\r\n\t\tinitialValue: T\r\n\t): T {\r\n\t\tlet accumulator = initialValue;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\taccumulator = callback(accumulator, this.get(i), i, this);\r\n\t\t}\r\n\t\treturn accumulator;\r\n\t}\r\n\r\n\t/**\r\n\t * Generates a string where every boolean is either a 0 or 1.\r\n\t */\r\n\ttoString() {\r\n\t\tlet result = ``;\r\n\t\tfor (let i = 0; i < this.size; i++) {\r\n\t\t\tresult += this.get(i) ? '1' : '0';\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from .toString() output\r\n\t */\r\n\tstatic fromString(value: string) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, value[i] == '1');\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a boolean array or number array\r\n\t */\r\n\tstatic fromArray(value: boolean[] | number[]) {\r\n\t\tconst array = new FastBooleanArray(value.length);\r\n\t\tfor (let i = 0; i < value.length; i++) {\r\n\t\t\tarray.set(i, !!value[i]);\r\n\t\t}\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a FastBooleanArray from a string, boolean array or number array\r\n\t */\r\n\tstatic from(value: string | boolean[] | number[]) {\r\n\t\tif (typeof value === 'string') {\r\n\t\t\treturn FastBooleanArray.fromString(value);\r\n\t\t}\r\n\r\n\t\treturn FastBooleanArray.fromArray(value);\r\n\t}\r\n}\r\n"],"mappings":"AAAA,IAAqBA,EAArB,MAAqBC,CAAiB,CAC9B,KACC,OAER,YAAYC,EAAc,CACzB,GAAI,CAACA,EACJ,MAAM,IAAI,MAAM,kDAAkD,EAEnE,KAAK,KAAOA,EACZ,KAAK,OAAS,IAAI,WAAW,KAAK,KAAKA,EAAO,CAAC,CAAC,CACjD,CAQA,IAAIC,EAAeC,EAAgB,CAClC,OAAIA,GACH,KAAK,OAAOD,GAAS,CAAC,GAAK,IAAMA,EAAQ,GAClC,KAEP,KAAK,OAAOA,GAAS,CAAC,GAAK,EAAE,IAAMA,EAAQ,IACpC,GAET,CASA,QAAQA,EAAeC,EAAgB,CACtC,GAAID,EAAQ,GAAKA,GAAS,KAAK,KAC9B,MAAM,IAAI,WAAW,qBAAqB,EAE3C,OAAO,KAAK,IAAIA,EAAOC,CAAK,CAC7B,CAMA,OAAOA,EAAgB,CACtB,KAAK,OAAO,KAAKA,EAAQ,IAAO,CAAI,CACrC,CAQA,IAAID,EAAe,CAClB,IAAME,EAAYF,IAAU,EACtBG,EAAWH,EAAQ,EACzB,OAAQ,KAAK,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,GAAU,KAAK,IAAIL,CAAC,EAAI,IAAM,IAE/B,OAAOK,CACR,CAKA,OAAO,WAAWZ,EAAe,CAChC,IAAMe,EAAQ,IAAIlB,EAAiBG,EAAM,MAAM,EAC/C,QAASO,EAAI,EAAGA,EAAIP,EAAM,OAAQO,IACjCQ,EAAM,IAAIR,EAAGP,EAAMO,CAAC,GAAK,GAAG,EAE7B,OAAOQ,CACR,CAKA,OAAO,UAAUf,EAA6B,CAC7C,IAAMe,EAAQ,IAAIlB,EAAiBG,EAAM,MAAM,EAC/C,QAASO,EAAI,EAAGA,EAAIP,EAAM,OAAQO,IACjCQ,EAAM,IAAIR,EAAG,CAAC,CAACP,EAAMO,CAAC,CAAC,EAExB,OAAOQ,CACR,CAKA,OAAO,KAAKf,EAAsC,CACjD,OAAI,OAAOA,GAAU,SACbH,EAAiB,WAAWG,CAAK,EAGlCH,EAAiB,UAAUG,CAAK,CACxC,CACD","names":["FastBooleanArray","_FastBooleanArray","size","index","value","byteIndex","bitIndex","newSize","newBuffer","other","byte","i","arr","target","prop","callback","result","initialValue","accumulator","array"]}
package/package.json CHANGED
@@ -1,49 +1,50 @@
1
- {
2
- "name": "fast-boolean-array",
3
- "version": "1.4.0",
4
- "homepage": "https://github.com/UltraCakeBakery/FastBooleanArray",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/UltraCakeBakery/FastBooleanArray.git"
8
- },
9
- "bugs": {
10
- "url": "https://github.com/UltraCakeBakery/FastBooleanArray/issues",
11
- "email": "fast-boolean-array@managing.software"
12
- },
13
- "type": "module",
14
- "main": "./dist/index.cjs",
15
- "module": "./dist/index.js",
16
- "types": "./dist/index.d.ts",
17
- "exports": {
18
- "import": {
19
- "types": "./dist/index.d.ts",
20
- "import": "./dist/index.js"
21
- },
22
- "require": {
23
- "types": "./dist/index.d.cts",
24
- "require": "./dist/index.cjs"
25
- }
26
- },
27
- "scripts": {
28
- "check": "npm run check:types",
29
- "check:types": "npx --yes @arethetypeswrong/cli --pack .",
30
- "build": "tsup src/index.ts --dts --format cjs,esm --clean --sourcemap"
31
- },
32
- "keywords": [
33
- "boolean",
34
- "array",
35
- "fast",
36
- "efficient",
37
- "map"
38
- ],
39
- "author": "Jack van der Bil <jack@managing.software> (https://jackvanderbilt.nl)",
40
- "license": "MIT",
41
- "description": "",
42
- "engines": {
43
- "node": ">=0.10.3"
44
- },
45
- "devDependencies": {
46
- "@types/node": "^22.10.2",
47
- "tsup": "^8.3.5"
48
- }
1
+ {
2
+ "name": "fast-boolean-array",
3
+ "version": "1.4.2",
4
+ "homepage": "https://github.com/UltraCakeBakery/FastBooleanArray",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/UltraCakeBakery/FastBooleanArray.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/UltraCakeBakery/FastBooleanArray/issues",
11
+ "email": "fast-boolean-array@managing.software"
12
+ },
13
+ "type": "module",
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.cts",
24
+ "require": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "check": "npm run check:types",
29
+ "check:types": "npx --yes @arethetypeswrong/cli --pack .",
30
+ "build": "tsup src/index.ts --dts --format cjs,esm --clean --sourcemap --minify"
31
+ },
32
+ "keywords": [
33
+ "boolean",
34
+ "array",
35
+ "fast",
36
+ "efficient",
37
+ "map"
38
+ ],
39
+ "author": "Jack van der Bil <jack@managing.software> (https://jackvanderbilt.nl)",
40
+ "license": "MIT",
41
+ "description": "",
42
+ "engines": {
43
+ "node": ">=0.10.3"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.10.2",
47
+ "tsup": "^8.3.5",
48
+ "typescript": "^5.7.2"
49
+ }
49
50
  }
package/.gitattributes DELETED
@@ -1,5 +0,0 @@
1
- * text=auto
2
-
3
- *.ts linguist-language=TypeScript
4
- *.js linguist-vendored=true
5
- *.md linguist-vendored=true