fast-boolean-array 1.4.1 → 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/dist/index.cjs +1 -267
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -246
- package/dist/index.js.map +1 -1
- package/package.json +49 -48
- package/.gitattributes +0 -5
package/dist/index.cjs
CHANGED
|
@@ -1,268 +1,2 @@
|
|
|
1
|
-
"
|
|
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
|
-
const byteIndex = index >>> 3;
|
|
79
|
-
const bitIndex = index & 7;
|
|
80
|
-
return (this.buffer[byteIndex] & 1 << bitIndex) !== 0;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
84
|
-
* @param {number} index - The index to get the boolean value of.
|
|
85
|
-
* @returns {boolean} The boolean value that was set.
|
|
86
|
-
* @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
87
|
-
*/
|
|
88
|
-
getSafe(index) {
|
|
89
|
-
if (index < 0 || index >= this.size) {
|
|
90
|
-
throw new RangeError("Index out of bounds");
|
|
91
|
-
}
|
|
92
|
-
return this.get(index);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Resizes the array to a new size, preserving existing data.
|
|
96
|
-
* @param {number} newSize - The new size of the array.
|
|
97
|
-
*/
|
|
98
|
-
resize(newSize) {
|
|
99
|
-
const newBuffer = new Uint8Array(Math.ceil(newSize / 8));
|
|
100
|
-
newBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));
|
|
101
|
-
this.buffer = newBuffer;
|
|
102
|
-
this.size = newSize;
|
|
103
|
-
}
|
|
104
|
-
get length() {
|
|
105
|
-
return this.size;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Compares this FastBooleanArray with another for equality.
|
|
109
|
-
* @param {FastBooleanArray} other - The other FastBooleanArray to compare.
|
|
110
|
-
* @returns {boolean} True if both arrays are equal, false otherwise.
|
|
111
|
-
*/
|
|
112
|
-
equals(other) {
|
|
113
|
-
if (this.size !== other.size) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
return this.buffer.every((byte, i) => byte === other.buffer[i]);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Makes the array iterable using `for...of`.
|
|
120
|
-
*/
|
|
121
|
-
*[Symbol.iterator]() {
|
|
122
|
-
for (let i = 0; i < this.size; i++) {
|
|
123
|
-
yield this.get(i);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Converts to a standard JavaScript array.
|
|
128
|
-
*/
|
|
129
|
-
toArray() {
|
|
130
|
-
const arr = new Array(this.size);
|
|
131
|
-
for (let i = 0; i < this.size; i++) {
|
|
132
|
-
arr[i] = this.get(i);
|
|
133
|
-
}
|
|
134
|
-
return arr;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Returns a proxy to the FastBooleanArray instance
|
|
138
|
-
* With this you can access indexes like on an actual array.
|
|
139
|
-
*/
|
|
140
|
-
accessLikeArray() {
|
|
141
|
-
return new Proxy(this, {
|
|
142
|
-
get: (target, prop) => {
|
|
143
|
-
if (typeof prop === "string" && !isNaN(Number(prop))) {
|
|
144
|
-
const index = Number(prop);
|
|
145
|
-
return target.get(index);
|
|
146
|
-
}
|
|
147
|
-
return target[prop];
|
|
148
|
-
},
|
|
149
|
-
set: (target, prop, value) => {
|
|
150
|
-
if (typeof prop === "string" && !isNaN(Number(prop))) {
|
|
151
|
-
const index = Number(prop);
|
|
152
|
-
return target.set(index, value);
|
|
153
|
-
}
|
|
154
|
-
return target[prop] = value;
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Applies a callback function to each element in the array.
|
|
160
|
-
* @param {Function} callback - The function to execute on each element.
|
|
161
|
-
*/
|
|
162
|
-
forEach(callback) {
|
|
163
|
-
for (let i = 0; i < this.size; i++) {
|
|
164
|
-
callback(this.get(i), i, this);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Creates a new array with the results of calling a provided function on every element.
|
|
169
|
-
* @param {Function} callback - The function to execute on each element.
|
|
170
|
-
*/
|
|
171
|
-
map(callback) {
|
|
172
|
-
const result = new Array(this.size);
|
|
173
|
-
for (let i = 0; i < this.size; i++) {
|
|
174
|
-
result[i] = callback(this.get(i), i, this);
|
|
175
|
-
}
|
|
176
|
-
return result;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Creates a new array with all elements that pass the test implemented by the provided function.
|
|
180
|
-
* @param {Function} callback - The function to test each element.
|
|
181
|
-
*/
|
|
182
|
-
filter(callback) {
|
|
183
|
-
const result = [];
|
|
184
|
-
for (let i = 0; i < this.size; i++) {
|
|
185
|
-
const value = this.get(i);
|
|
186
|
-
if (callback(value, i, this)) {
|
|
187
|
-
result.push(value);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return result;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Tests whether at least one element in the array passes the test implemented by the provided function.
|
|
194
|
-
* @param {Function} callback - The function to test each element.
|
|
195
|
-
*/
|
|
196
|
-
some(callback) {
|
|
197
|
-
for (let i = 0; i < this.size; i++) {
|
|
198
|
-
if (callback(this.get(i), i, this)) {
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Tests whether all elements in the array pass the test implemented by the provided function.
|
|
206
|
-
* @param {Function} callback - The function to test each element.
|
|
207
|
-
*/
|
|
208
|
-
every(callback) {
|
|
209
|
-
for (let i = 0; i < this.size; i++) {
|
|
210
|
-
if (!callback(this.get(i), i, this)) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Reduces the array to a single value by applying a function to each element.
|
|
218
|
-
* @param {Function} callback - The function to execute on each element.
|
|
219
|
-
* @param {any} initialValue - The initial value for the accumulator.
|
|
220
|
-
*/
|
|
221
|
-
reduce(callback, initialValue) {
|
|
222
|
-
let accumulator = initialValue;
|
|
223
|
-
for (let i = 0; i < this.size; i++) {
|
|
224
|
-
accumulator = callback(accumulator, this.get(i), i, this);
|
|
225
|
-
}
|
|
226
|
-
return accumulator;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Generates a string where every boolean is either a 0 or 1.
|
|
230
|
-
*/
|
|
231
|
-
toString() {
|
|
232
|
-
let result = ``;
|
|
233
|
-
for (let i = 0; i < this.size; i++) {
|
|
234
|
-
result += this.get(i) ? "1" : "0";
|
|
235
|
-
}
|
|
236
|
-
return result;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Returns a FastBooleanArray from .toString() output
|
|
240
|
-
*/
|
|
241
|
-
static fromString(value) {
|
|
242
|
-
const array = new _FastBooleanArray(value.length);
|
|
243
|
-
for (let i = 0; i < value.length; i++) {
|
|
244
|
-
array.set(i, value[i] == "1");
|
|
245
|
-
}
|
|
246
|
-
return array;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Returns a FastBooleanArray from a boolean array or number array
|
|
250
|
-
*/
|
|
251
|
-
static fromArray(value) {
|
|
252
|
-
const array = new _FastBooleanArray(value.length);
|
|
253
|
-
for (let i = 0; i < value.length; i++) {
|
|
254
|
-
array.set(i, !!value[i]);
|
|
255
|
-
}
|
|
256
|
-
return array;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Returns a FastBooleanArray from a string, boolean array or number array
|
|
260
|
-
*/
|
|
261
|
-
static from(value) {
|
|
262
|
-
if (typeof value === "string") {
|
|
263
|
-
return _FastBooleanArray.fromString(value);
|
|
264
|
-
}
|
|
265
|
-
return _FastBooleanArray.fromArray(value);
|
|
266
|
-
}
|
|
267
|
-
};
|
|
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)}};
|
|
268
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.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\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;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,OAA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ACA,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":"4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAqBE,EAArB,MAAqBE,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,OAAOE,CAAS,EAAK,GAAKC,KAAe,CACvD,CAQA,QAAQH,EAAe,CACtB,GAAIA,EAAQ,GAAKA,GAAS,KAAK,KAC9B,MAAM,IAAI,WAAW,q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AM,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":["src_exports","__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,247 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
const byteIndex = index >>> 3;
|
|
55
|
-
const bitIndex = index & 7;
|
|
56
|
-
return (this.buffer[byteIndex] & 1 << bitIndex) !== 0;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
60
|
-
* @param {number} index - The index to get the boolean value of.
|
|
61
|
-
* @returns {boolean} The boolean value that was set.
|
|
62
|
-
* @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
|
|
63
|
-
*/
|
|
64
|
-
getSafe(index) {
|
|
65
|
-
if (index < 0 || index >= this.size) {
|
|
66
|
-
throw new RangeError("Index out of bounds");
|
|
67
|
-
}
|
|
68
|
-
return this.get(index);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Resizes the array to a new size, preserving existing data.
|
|
72
|
-
* @param {number} newSize - The new size of the array.
|
|
73
|
-
*/
|
|
74
|
-
resize(newSize) {
|
|
75
|
-
const newBuffer = new Uint8Array(Math.ceil(newSize / 8));
|
|
76
|
-
newBuffer.set(this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length)));
|
|
77
|
-
this.buffer = newBuffer;
|
|
78
|
-
this.size = newSize;
|
|
79
|
-
}
|
|
80
|
-
get length() {
|
|
81
|
-
return this.size;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Compares this FastBooleanArray with another for equality.
|
|
85
|
-
* @param {FastBooleanArray} other - The other FastBooleanArray to compare.
|
|
86
|
-
* @returns {boolean} True if both arrays are equal, false otherwise.
|
|
87
|
-
*/
|
|
88
|
-
equals(other) {
|
|
89
|
-
if (this.size !== other.size) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
return this.buffer.every((byte, i) => byte === other.buffer[i]);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Makes the array iterable using `for...of`.
|
|
96
|
-
*/
|
|
97
|
-
*[Symbol.iterator]() {
|
|
98
|
-
for (let i = 0; i < this.size; i++) {
|
|
99
|
-
yield this.get(i);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Converts to a standard JavaScript array.
|
|
104
|
-
*/
|
|
105
|
-
toArray() {
|
|
106
|
-
const arr = new Array(this.size);
|
|
107
|
-
for (let i = 0; i < this.size; i++) {
|
|
108
|
-
arr[i] = this.get(i);
|
|
109
|
-
}
|
|
110
|
-
return arr;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Returns a proxy to the FastBooleanArray instance
|
|
114
|
-
* With this you can access indexes like on an actual array.
|
|
115
|
-
*/
|
|
116
|
-
accessLikeArray() {
|
|
117
|
-
return new Proxy(this, {
|
|
118
|
-
get: (target, prop) => {
|
|
119
|
-
if (typeof prop === "string" && !isNaN(Number(prop))) {
|
|
120
|
-
const index = Number(prop);
|
|
121
|
-
return target.get(index);
|
|
122
|
-
}
|
|
123
|
-
return target[prop];
|
|
124
|
-
},
|
|
125
|
-
set: (target, prop, value) => {
|
|
126
|
-
if (typeof prop === "string" && !isNaN(Number(prop))) {
|
|
127
|
-
const index = Number(prop);
|
|
128
|
-
return target.set(index, value);
|
|
129
|
-
}
|
|
130
|
-
return target[prop] = value;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Applies a callback function to each element in the array.
|
|
136
|
-
* @param {Function} callback - The function to execute on each element.
|
|
137
|
-
*/
|
|
138
|
-
forEach(callback) {
|
|
139
|
-
for (let i = 0; i < this.size; i++) {
|
|
140
|
-
callback(this.get(i), i, this);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Creates a new array with the results of calling a provided function on every element.
|
|
145
|
-
* @param {Function} callback - The function to execute on each element.
|
|
146
|
-
*/
|
|
147
|
-
map(callback) {
|
|
148
|
-
const result = new Array(this.size);
|
|
149
|
-
for (let i = 0; i < this.size; i++) {
|
|
150
|
-
result[i] = callback(this.get(i), i, this);
|
|
151
|
-
}
|
|
152
|
-
return result;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Creates a new array with all elements that pass the test implemented by the provided function.
|
|
156
|
-
* @param {Function} callback - The function to test each element.
|
|
157
|
-
*/
|
|
158
|
-
filter(callback) {
|
|
159
|
-
const result = [];
|
|
160
|
-
for (let i = 0; i < this.size; i++) {
|
|
161
|
-
const value = this.get(i);
|
|
162
|
-
if (callback(value, i, this)) {
|
|
163
|
-
result.push(value);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return result;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Tests whether at least one element in the array passes the test implemented by the provided function.
|
|
170
|
-
* @param {Function} callback - The function to test each element.
|
|
171
|
-
*/
|
|
172
|
-
some(callback) {
|
|
173
|
-
for (let i = 0; i < this.size; i++) {
|
|
174
|
-
if (callback(this.get(i), i, this)) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Tests whether all elements in the array pass the test implemented by the provided function.
|
|
182
|
-
* @param {Function} callback - The function to test each element.
|
|
183
|
-
*/
|
|
184
|
-
every(callback) {
|
|
185
|
-
for (let i = 0; i < this.size; i++) {
|
|
186
|
-
if (!callback(this.get(i), i, this)) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Reduces the array to a single value by applying a function to each element.
|
|
194
|
-
* @param {Function} callback - The function to execute on each element.
|
|
195
|
-
* @param {any} initialValue - The initial value for the accumulator.
|
|
196
|
-
*/
|
|
197
|
-
reduce(callback, initialValue) {
|
|
198
|
-
let accumulator = initialValue;
|
|
199
|
-
for (let i = 0; i < this.size; i++) {
|
|
200
|
-
accumulator = callback(accumulator, this.get(i), i, this);
|
|
201
|
-
}
|
|
202
|
-
return accumulator;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Generates a string where every boolean is either a 0 or 1.
|
|
206
|
-
*/
|
|
207
|
-
toString() {
|
|
208
|
-
let result = ``;
|
|
209
|
-
for (let i = 0; i < this.size; i++) {
|
|
210
|
-
result += this.get(i) ? "1" : "0";
|
|
211
|
-
}
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Returns a FastBooleanArray from .toString() output
|
|
216
|
-
*/
|
|
217
|
-
static fromString(value) {
|
|
218
|
-
const array = new _FastBooleanArray(value.length);
|
|
219
|
-
for (let i = 0; i < value.length; i++) {
|
|
220
|
-
array.set(i, value[i] == "1");
|
|
221
|
-
}
|
|
222
|
-
return array;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Returns a FastBooleanArray from a boolean array or number array
|
|
226
|
-
*/
|
|
227
|
-
static fromArray(value) {
|
|
228
|
-
const array = new _FastBooleanArray(value.length);
|
|
229
|
-
for (let i = 0; i < value.length; i++) {
|
|
230
|
-
array.set(i, !!value[i]);
|
|
231
|
-
}
|
|
232
|
-
return array;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Returns a FastBooleanArray from a string, boolean array or number array
|
|
236
|
-
*/
|
|
237
|
-
static from(value) {
|
|
238
|
-
if (typeof value === "string") {
|
|
239
|
-
return _FastBooleanArray.fromString(value);
|
|
240
|
-
}
|
|
241
|
-
return _FastBooleanArray.fromArray(value);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
export {
|
|
245
|
-
FastBooleanArray as default
|
|
246
|
-
};
|
|
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};
|
|
247
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\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,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,qBAAqB;AAAA,IAC3C;AACA,WAAO,KAAK,IAAI,OAAO,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,OAAgB;AACtB,SAAK,OAAO,KAAK,QAAQ,MAAO,CAAI;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,OAAe;AAClB,UAAM,YAAY,UAAU;AAC5B,UAAM,WAAW,QAAQ;AACzB,YAAQ,KAAK,OAAO,SAA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,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,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AC,EAAGA,EAAG,IAAI,EACjC,MAAO,GAGT,MAAO,EACR,CAOA,OACCI,EACAE,EACI,CACJ,IAAIC,EAAcD,EAClB,QAASN,EAAI,EAAGA,EAAI,KAAK,KAAMA,IAC9BO,EAAcH,EAASG,EAAa,KAAK,IAAIP,CAAC,EAAGA,EAAG,IAAI,EAEzD,OAAOO,CACR,CAKA,UAAW,CACV,IAAIF,EAAS,GACb,QAASL,EAAI,EAAGA,EAAI,KAAK,KAAMA,IAC9BK,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.
|
|
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
|
}
|