fast-boolean-array 1.7.0 → 2.0.0

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
@@ -1,4 +1,4 @@
1
- # Fast Boolean Array ![Build](https://github.com/UltraCakeBakery/FastBooleanArray/actions/workflows/ci.yml/badge.svg?event=push)
1
+ # Fast Boolean Array ![Build](https://github.com/UltraCakeBakery/FastBooleanArray/actions/workflows/tests.yml/badge.svg?event=push)
2
2
 
3
3
  In JavaScript, when working with large arrays of boolean values, a common challenge is efficiently indexing and retrieving these values. Using a regular JavaScript array to store booleans is straightforward, but it is memory-inefficient. While booleans are conceptually 1-bit values, JavaScript engines, like V8 (in Chrome and Node.js), allocate 1 byte (8 bits) per boolean for optimization purposes. This can waste a significant amount of memory when dealing with large arrays.
4
4
 
@@ -10,9 +10,7 @@ For detailed benchmark results, see below.
10
10
 
11
11
  - **Memory Efficiency**: Stores booleans in bits rather than bytes, drastically reducing memory usage.
12
12
  - **Fast Set Performance**: Up to 10x faster sets for fast data re-mapping.
13
- - **Familiar API**: `Map` and `Set` like API for minimal learning curve. Intuitive helper functions, and works in `for.. of`.
14
- - **Array like interface**: call `.accessLikeArray()` to access it like an array`someArray[index]` (beware of the performance penalty caused by the Proxy)!
15
-
13
+ - **Familiar API**: `Map` and `Set` like API for minimal learning curve. Intuitive Array like helper functions, and works in `for.. of`.
16
14
  ---
17
15
 
18
16
  ## Usage example:
@@ -21,7 +19,6 @@ Here's how to use the Fast Boolean Array:
21
19
 
22
20
  ```javascript
23
21
  import BooleanArray from "fast-boolean-array";
24
- // const BooleanArray = require('fast-boolean-array'); commonjs works too.
25
22
 
26
23
  // Create a new BooleanArray with the desired length
27
24
  const booleans = new BooleanArray(2);
@@ -85,7 +82,7 @@ Gets the boolean value at the specified index.
85
82
 
86
83
  # Performance Breakdown
87
84
 
88
- 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.
85
+ 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. Generally you will notice the trend that as the size of the array grows, so does the justification of using our library instead of a regular vanilla JavaScript array.
89
86
 
90
87
  ## Performance Breakdown
91
88
 
@@ -111,7 +108,7 @@ As useless as having just 1 boolean stored in an array might be, For **1 boolean
111
108
  | Get Vanilla Array | 0.00149000 | N/A | 100 |
112
109
  | Get Fast Boolean Array | 0.00581000 | N/A | 100 |
113
110
 
114
- **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**.
111
+ 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**.
115
112
 
116
113
  ---
117
114
 
@@ -0,0 +1,110 @@
1
+ //#region src/index.d.ts
2
+ declare class FastBooleanArray {
3
+ size: number;
4
+ private buffer;
5
+ constructor(size: number);
6
+ /**
7
+ * Sets a boolean value at the specified index.
8
+ * @param {number} index - The index to set the boolean value at.
9
+ * @param {number} value - The boolean value to set the `index`.
10
+ * @returns {boolean} The boolean value that was set.
11
+ */
12
+ set(index: number, value: boolean): boolean;
13
+ /**
14
+ * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
15
+ * @param {number} index - The index to set the boolean value at.
16
+ * @param {number} value - The boolean value to set the `index`.
17
+ * @returns {boolean} The boolean value that was set.
18
+ * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
19
+ */
20
+ setSafe(index: number, value: boolean): boolean;
21
+ /**
22
+ * Sets all bits to the specified boolean value.
23
+ * @param {boolean} value - The boolean value to set all bits to.
24
+ */
25
+ setAll(value: boolean): void;
26
+ /**
27
+ * Gets a boolean value at the specified index.
28
+ * @param {number} index - The index to get the boolean value of.
29
+ * @returns {boolean} The boolean value that was set.
30
+ * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
31
+ */
32
+ get(index: number): boolean;
33
+ /**
34
+ * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
35
+ * @param {number} index - The index to get the boolean value of.
36
+ * @returns {boolean} The boolean value that was set.
37
+ * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
38
+ */
39
+ getSafe(index: number): boolean;
40
+ /**
41
+ * Resizes the array to a new size, preserving existing data.
42
+ * @param {number} newSize - The new size of the array.
43
+ */
44
+ resize(newSize: number): void;
45
+ get length(): number;
46
+ /**
47
+ * Compares this FastBooleanArray with another for equality.
48
+ * @param {FastBooleanArray} other - The other FastBooleanArray to compare.
49
+ * @returns {boolean} True if both arrays are equal, false otherwise.
50
+ */
51
+ equals(other: FastBooleanArray): boolean;
52
+ /**
53
+ * Makes the array iterable using `for...of`.
54
+ */
55
+ [Symbol.iterator](): Generator<boolean, void, unknown>;
56
+ /**
57
+ * Converts to a standard JavaScript array.
58
+ */
59
+ toArray(): any[];
60
+ /**
61
+ * Applies a callback function to each element in the array.
62
+ * @param {Function} callback - The function to execute on each element.
63
+ */
64
+ forEach(callback: (value: boolean, index: number, array: FastBooleanArray) => void): void;
65
+ /**
66
+ * Creates a new array with the results of calling a provided function on every element.
67
+ * @param {Function} callback - The function to execute on each element.
68
+ */
69
+ map(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): any[];
70
+ /**
71
+ * Creates a new array with all elements that pass the test implemented by the provided function.
72
+ * @param {Function} callback - The function to test each element.
73
+ */
74
+ filter(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean[];
75
+ /**
76
+ * Tests whether at least one element in the array passes the test implemented by the provided function.
77
+ * @param {Function} callback - The function to test each element.
78
+ */
79
+ some(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean;
80
+ /**
81
+ * Tests whether all elements in the array pass the test implemented by the provided function.
82
+ * @param {Function} callback - The function to test each element.
83
+ */
84
+ every(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean;
85
+ /**
86
+ * Reduces the array to a single value by applying a function to each element.
87
+ * @param {Function} callback - The function to execute on each element.
88
+ * @param {any} initialValue - The initial value for the accumulator.
89
+ */
90
+ reduce<T>(callback: (accumulator: T, value: boolean, index: number, array: FastBooleanArray) => T, initialValue: T): T;
91
+ /**
92
+ * Generates a string where every boolean is either a 0 or 1.
93
+ */
94
+ toString(): string;
95
+ /**
96
+ * Returns a FastBooleanArray from .toString() output
97
+ */
98
+ static fromString(value: string): FastBooleanArray;
99
+ /**
100
+ * Returns a FastBooleanArray from a boolean array or number array
101
+ */
102
+ static fromArray(value: boolean[] | number[]): FastBooleanArray;
103
+ /**
104
+ * Returns a FastBooleanArray from a string, boolean array or number array
105
+ */
106
+ static from(value: string | boolean[] | number[]): FastBooleanArray;
107
+ }
108
+ //#endregion
109
+ export { FastBooleanArray as default };
110
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ const e=`Index out of bounds`,t=`FastBooleanArray size must be greater than 0`;var n=class n{size;buffer;constructor(e){if(!e)throw RangeError(t);this.size=e,this.buffer=new Uint8Array(Math.ceil(e/8))}set(e,t){return t?(this.buffer[e>>3]|=1<<(e&7),!0):(this.buffer[e>>3]&=~(1<<(e&7)),!1)}setSafe(t,n){if(t<0||t>=this.size)throw RangeError(e);return this.set(t,n)}setAll(e){this.buffer.fill(e?255:0);let t=this.size&7;if(e&&t!==0){let e=this.buffer.length-1;this.buffer[e]&=(1<<t)-1}}get(e){return!!(this.buffer[e>>3]>>(e&7)&1)}getSafe(t){if(t<0||t>=this.size)throw RangeError(e);return this.get(t)}resize(e){if(e<=0)throw RangeError(t);let n=this.size;if(e===n)return;let r=this.buffer.length,i=e+7>>3;if(i===r){if(this.size=e,e<n){let t=e&7;t!==0&&(this.buffer[i-1]&=(1<<t)-1)}return}let a=this.buffer.slice(0,Math.min(r,i));if(i>a.length){let e=new Uint8Array(i);e.set(a),a=e}if(this.size=e,this.buffer=a,e<n){let t=e&7;t!==0&&(this.buffer[i-1]&=(1<<t)-1)}}get length(){return this.size}equals(e){if(this.size!==e.size)return!1;let t=this.size>>3;for(let n=0;n<t;n++)if(this.buffer[n]!==e.buffer[n])return!1;let n=this.size&7;if(n===0)return!0;let r=(1<<n)-1;return(this.buffer[t]&r)===(e.buffer[t]&r)}*[Symbol.iterator](){for(let e=0;e<this.size;e++)yield this.get(e)}toArray(){let e=Array(this.size);for(let t=0;t<this.size;t++)e[t]=this.get(t);return e}forEach(e){for(let t=0;t<this.size;t++)e(this.get(t),t,this)}map(e){let t=Array(this.size);for(let n=0;n<this.size;n++)t[n]=e(this.get(n),n,this);return t}filter(e){let t=[];for(let n=0;n<this.size;n++){let r=this.get(n);e(r,n,this)&&t.push(r)}return t}some(e){for(let t=0;t<this.size;t++)if(e(this.get(t),t,this))return!0;return!1}every(e){for(let t=0;t<this.size;t++)if(!e(this.get(t),t,this))return!1;return!0}reduce(e,t){let n=t;for(let t=0;t<this.size;t++)n=e(n,this.get(t),t,this);return n}toString(){let e=Array(this.size),t=0,n=this.size>>3;for(let r=0;r<n;r++){let n=this.buffer[r];e[t++]=n&1?`1`:`0`,e[t++]=n&2?`1`:`0`,e[t++]=n&4?`1`:`0`,e[t++]=n&8?`1`:`0`,e[t++]=n&16?`1`:`0`,e[t++]=n&32?`1`:`0`,e[t++]=n&64?`1`:`0`,e[t++]=n&128?`1`:`0`}let r=this.size&7;if(r){let i=this.buffer[n];for(let n=0;n<r;n++)e[t++]=i&1<<n?`1`:`0`}return e.join(``)}static fromString(e){let t=new n(e.length);for(let n=0;n<e.length;n++)t.set(n,e[n]==`1`);return t}static fromArray(e){let t=new n(e.length);for(let n=0;n<e.length;n++)t.set(n,!!e[n]);return t}static from(e){return typeof e==`string`?n.fromString(e):n.fromArray(e)}};export{n as default};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["const ERROR_OUT_OF_BOUNDS = \"Index out of bounds\";\r\nconst ERROR_INVALID_SIZE = \"FastBooleanArray size must be greater than 0\";\r\n\r\nexport default class FastBooleanArray {\r\n public size: number;\r\n private buffer: Uint8Array;\r\n\r\n constructor(size: number) {\r\n if (!size) {\r\n throw new RangeError(ERROR_INVALID_SIZE);\r\n }\r\n\r\n this.size = size;\r\n this.buffer = new Uint8Array(Math.ceil(size / 8)); // Allocate memory\r\n }\r\n\r\n /**\r\n * Sets a boolean value at the specified index.\r\n * @param {number} index - The index to set the boolean value at.\r\n * @param {number} value - The boolean value to set the `index`.\r\n * @returns {boolean} The boolean value that was set.\r\n */\r\n set(index: number, value: boolean) {\r\n if (value) {\r\n this.buffer[index >> 3] |= 1 << (index & 7); // Set bit\r\n return true;\r\n }\r\n\r\n this.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit\r\n return false;\r\n }\r\n\r\n /**\r\n * 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 * @param {number} index - The index to set the boolean value at.\r\n * @param {number} value - The boolean value to set the `index`.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n setSafe(index: number, value: boolean) {\r\n if (index < 0 || index >= this.size) {\r\n throw new RangeError(ERROR_OUT_OF_BOUNDS);\r\n }\r\n return this.set(index, value);\r\n }\r\n\r\n /**\r\n * Sets all bits to the specified boolean value.\r\n * @param {boolean} value - The boolean value to set all bits to.\r\n */\r\n setAll(value: boolean) {\r\n this.buffer.fill(value ? 0xff : 0x00);\r\n\r\n const rem = this.size & 7;\r\n if (value && rem !== 0) {\r\n const last = this.buffer.length - 1;\r\n this.buffer[last] &= (1 << rem) - 1;\r\n }\r\n }\r\n\r\n /**\r\n * Gets a boolean value at the specified index.\r\n * @param {number} index - The index to get the boolean value of.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n get(index: number) {\r\n return (this.buffer[index >> 3] >> (index & 7)) & 1 ? true : false;\r\n }\r\n\r\n /**\r\n * 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 * @param {number} index - The index to get the boolean value of.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n getSafe(index: number) {\r\n if (index < 0 || index >= this.size) {\r\n throw new RangeError(ERROR_OUT_OF_BOUNDS);\r\n }\r\n return this.get(index);\r\n }\r\n\r\n /**\r\n * Resizes the array to a new size, preserving existing data.\r\n * @param {number} newSize - The new size of the array.\r\n */\r\n resize(newSize: number) {\r\n if (newSize <= 0) throw new RangeError(ERROR_INVALID_SIZE);\r\n\r\n const oldSize = this.size;\r\n if (newSize === oldSize) return;\r\n\r\n const oldLen = this.buffer.length;\r\n const newLen = (newSize + 7) >> 3;\r\n\r\n if (newLen === oldLen) {\r\n this.size = newSize;\r\n\r\n if (newSize < oldSize) {\r\n const rem = newSize & 7;\r\n if (rem !== 0) this.buffer[newLen - 1] &= (1 << rem) - 1;\r\n }\r\n return;\r\n }\r\n\r\n let newBuffer = this.buffer.slice(0, Math.min(oldLen, newLen));\r\n\r\n if (newLen > newBuffer.length) {\r\n const grown = new Uint8Array(newLen);\r\n grown.set(newBuffer);\r\n newBuffer = grown;\r\n }\r\n\r\n this.size = newSize;\r\n this.buffer = newBuffer;\r\n\r\n if (newSize < oldSize) {\r\n const rem = newSize & 7;\r\n if (rem !== 0) this.buffer[newLen - 1] &= (1 << rem) - 1;\r\n }\r\n }\r\n\r\n get length() {\r\n return this.size;\r\n }\r\n\r\n /**\r\n * Compares this FastBooleanArray with another for equality.\r\n * @param {FastBooleanArray} other - The other FastBooleanArray to compare.\r\n * @returns {boolean} True if both arrays are equal, false otherwise.\r\n */\r\n equals(other: FastBooleanArray) {\r\n if (this.size !== other.size) return false;\r\n\r\n const fullBytes = this.size >> 3;\r\n for (let i = 0; i < fullBytes; i++) {\r\n if (this.buffer[i] !== other.buffer[i]) return false;\r\n }\r\n\r\n const rem = this.size & 7;\r\n if (rem === 0) return true;\r\n\r\n const mask = (1 << rem) - 1; // keep only valid bits in last byte\r\n return (this.buffer[fullBytes] & mask) === (other.buffer[fullBytes] & mask);\r\n }\r\n\r\n /**\r\n * Makes the array iterable using `for...of`.\r\n */\r\n *[Symbol.iterator]() {\r\n for (let i = 0; i < this.size; i++) {\r\n yield this.get(i);\r\n }\r\n }\r\n\r\n /**\r\n * Converts to a standard JavaScript array.\r\n */\r\n toArray() {\r\n const arr = new Array(this.size);\r\n for (let i = 0; i < this.size; i++) {\r\n arr[i] = this.get(i);\r\n }\r\n return arr;\r\n }\r\n\r\n /**\r\n * Applies a callback function to each element in the array.\r\n * @param {Function} callback - The function to execute on each element.\r\n */\r\n forEach(\r\n callback: (value: boolean, index: number, array: FastBooleanArray) => void,\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n callback(this.get(i), i, this);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new array with the results of calling a provided function on every element.\r\n * @param {Function} callback - The function to execute on each element.\r\n */\r\n map(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray,\r\n ) => boolean,\r\n ) {\r\n const result = new Array(this.size);\r\n for (let i = 0; i < this.size; i++) {\r\n result[i] = callback(this.get(i), i, this);\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new array with all elements that pass the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n filter(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray,\r\n ) => boolean,\r\n ) {\r\n const result: boolean[] = [];\r\n for (let i = 0; i < this.size; i++) {\r\n const value = this.get(i);\r\n if (callback(value, i, this)) {\r\n result.push(value);\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Tests whether at least one element in the array passes the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n some(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray,\r\n ) => boolean,\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n if (callback(this.get(i), i, this)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Tests whether all elements in the array pass the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n every(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray,\r\n ) => boolean,\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n if (!callback(this.get(i), i, this)) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Reduces the array to a single value by applying a function to each element.\r\n * @param {Function} callback - The function to execute on each element.\r\n * @param {any} initialValue - The initial value for the accumulator.\r\n */\r\n reduce<T>(\r\n callback: (\r\n accumulator: T,\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray,\r\n ) => T,\r\n initialValue: T,\r\n ): T {\r\n let accumulator = initialValue;\r\n for (let i = 0; i < this.size; i++) {\r\n accumulator = callback(accumulator, this.get(i), i, this);\r\n }\r\n return accumulator;\r\n }\r\n\r\n /**\r\n * Generates a string where every boolean is either a 0 or 1.\r\n */\r\n toString() {\r\n const out = new Array(this.size);\r\n let k = 0;\r\n\r\n const fullBytes = this.size >> 3;\r\n for (let i = 0; i < fullBytes; i++) {\r\n const b = this.buffer[i];\r\n out[k++] = b & 1 ? \"1\" : \"0\";\r\n out[k++] = b & 2 ? \"1\" : \"0\";\r\n out[k++] = b & 4 ? \"1\" : \"0\";\r\n out[k++] = b & 8 ? \"1\" : \"0\";\r\n out[k++] = b & 16 ? \"1\" : \"0\";\r\n out[k++] = b & 32 ? \"1\" : \"0\";\r\n out[k++] = b & 64 ? \"1\" : \"0\";\r\n out[k++] = b & 128 ? \"1\" : \"0\";\r\n }\r\n\r\n const rem = this.size & 7;\r\n if (rem) {\r\n const b = this.buffer[fullBytes];\r\n for (let bit = 0; bit < rem; bit++) {\r\n out[k++] = b & (1 << bit) ? \"1\" : \"0\";\r\n }\r\n }\r\n\r\n return out.join(\"\");\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from .toString() output\r\n */\r\n static fromString(value: string) {\r\n const array = new FastBooleanArray(value.length);\r\n for (let i = 0; i < value.length; i++) {\r\n array.set(i, value[i] == \"1\");\r\n }\r\n return array;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from a boolean array or number array\r\n */\r\n static fromArray(value: boolean[] | number[]) {\r\n const array = new FastBooleanArray(value.length);\r\n for (let i = 0; i < value.length; i++) {\r\n array.set(i, !!value[i]);\r\n }\r\n return array;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from a string, boolean array or number array\r\n */\r\n static from(value: string | boolean[] | number[]) {\r\n if (typeof value === \"string\") {\r\n return FastBooleanArray.fromString(value);\r\n }\r\n\r\n return FastBooleanArray.fromArray(value);\r\n }\r\n}\r\n"],"mappings":"AAAA,MAAM,EAAsB,sBACtB,EAAqB,+CAE3B,IAAqB,EAArB,MAAqB,CAAiB,CACpC,KACA,OAEA,YAAY,EAAc,CACxB,GAAI,CAAC,EACH,MAAU,WAAW,CAAkB,EAGzC,KAAK,KAAO,EACZ,KAAK,OAAS,IAAI,WAAW,KAAK,KAAK,EAAO,CAAC,CAAC,CAClD,CAQA,IAAI,EAAe,EAAgB,CAOjC,OANI,GACF,KAAK,OAAO,GAAS,IAAM,IAAM,EAAQ,GAClC,KAGT,KAAK,OAAO,GAAS,IAAM,EAAE,IAAM,EAAQ,IACpC,GACT,CASA,QAAQ,EAAe,EAAgB,CACrC,GAAI,EAAQ,GAAK,GAAS,KAAK,KAC7B,MAAU,WAAW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,EAAG,EAAI,EAAM,OAAQ,IAChC,EAAM,IAAI,EAAG,CAAC,CAAC,EAAM,EAAE,EAEzB,OAAO,CACT,CAKA,OAAO,KAAK,EAAsC,CAKhD,OAJI,OAAO,GAAU,SACZ,EAAiB,WAAW,CAAK,EAGnC,EAAiB,UAAU,CAAK,CACzC,CACF"}
package/package.json CHANGED
@@ -1,52 +1,48 @@
1
- {
2
- "name": "fast-boolean-array",
3
- "version": "1.7.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
- "test": "vitest",
29
- "check-types": "npx --yes @arethetypeswrong/cli --pack .",
30
- "build": "tsup src/index.ts --dts --format cjs,esm --clean --sourcemap --minify",
31
- "publish": "npm publish"
32
- },
33
- "keywords": [
34
- "boolean",
35
- "array",
36
- "fast",
37
- "efficient",
38
- "map"
39
- ],
40
- "author": "Jack van der Bil <jack@managing.software> (https://jackvanderbilt.nl)",
41
- "license": "MIT",
42
- "description": "",
43
- "engines": {
44
- "node": ">=0.10.3"
45
- },
46
- "devDependencies": {
47
- "@types/node": "^24.0.3",
48
- "tsup": "^8.4.0",
49
- "typescript": "^5.8.3",
50
- "vitest": "^3.1.2"
51
- }
52
- }
1
+ {
2
+ "name": "fast-boolean-array",
3
+ "version": "2.0.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.mjs",
15
+ "types": "./dist/index.d.mts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "test": "vitest",
24
+ "bench": "node bench.js",
25
+ "build": "npx tsdown src/index.ts --dts --clean --sourcemap --minify --target node26",
26
+ "publish": "npm publish"
27
+ },
28
+ "keywords": [
29
+ "boolean",
30
+ "array",
31
+ "fast",
32
+ "efficient",
33
+ "map"
34
+ ],
35
+ "author": "Jack van der Bil <jack@managing.software> (https://jackvanderbilt.nl)",
36
+ "license": "MIT",
37
+ "description": "A fast and memory-efficient JavaScript array alternative for storing Boolean's, enabling fast indexing and retrieval.",
38
+ "engines": {
39
+ "node": ">=26.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^25.9.1",
43
+ "fast-boolean-array": "^1.7.1",
44
+ "tsdown": "^0.22.1",
45
+ "typescript": "^6.0.3",
46
+ "vitest": "^4.1.8"
47
+ }
48
+ }
@@ -0,0 +1,2 @@
1
+ allowBuilds:
2
+ esbuild: true
package/dist/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(n,e)=>{for(var r in e)a(n,r,{get:e[r],enumerable:!0})},b=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of l(e))!f.call(n,s)&&s!==r&&a(n,s,{get:()=>e[s],enumerable:!(t=u(e,s))||t.enumerable});return n};var y=n=>b(a({},"__esModule",{value:!0}),n);var g={};h(g,{default:()=>i});module.exports=y(g);var o="Index out of bounds",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(o);return this.set(e,r)}setAll(e){this.buffer.fill(e?255:0)}get(e){return!!(this.buffer[e>>3]>>(e&7)&1)}getSafe(e){if(e<0||e>=this.size)throw new RangeError(o);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.size=e,this.buffer=r}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);e.set(s,t)}else e[r]=t;return!0}})}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)}};
2
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["const ERROR_OUT_OF_BOUNDS = \"Index out of bounds\";\r\n\r\nexport default class FastBooleanArray {\r\n public size: number;\r\n private buffer: Uint8Array;\r\n\r\n constructor(size: number) {\r\n if (!size) {\r\n throw new Error(\"FastBooleanArray must have a size greater than 0\");\r\n }\r\n this.size = size;\r\n this.buffer = new Uint8Array(Math.ceil(size / 8)); // Allocate memory\r\n }\r\n\r\n /**\r\n * Sets a boolean value at the specified index.\r\n * @param {number} index - The index to set the boolean value at.\r\n * @param {number} value - The boolean value to set the `index`.\r\n * @returns {boolean} The boolean value that was set.\r\n */\r\n set(index: number, value: boolean) {\r\n if (value) {\r\n this.buffer[index >> 3] |= 1 << (index & 7); // Set bit\r\n return true;\r\n } else {\r\n this.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * 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 * @param {number} index - The index to set the boolean value at.\r\n * @param {number} value - The boolean value to set the `index`.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n setSafe(index: number, value: boolean) {\r\n if (index < 0 || index >= this.size) {\r\n throw new RangeError(ERROR_OUT_OF_BOUNDS);\r\n }\r\n return this.set(index, value);\r\n }\r\n\r\n /**\r\n * Sets all bits to the specified boolean value.\r\n * @param {boolean} value - The boolean value to set all bits to.\r\n */\r\n setAll(value: boolean) {\r\n this.buffer.fill(value ? 0xff : 0x00);\r\n }\r\n\r\n /**\r\n * Gets a boolean value at the specified index.\r\n * @param {number} index - The index to get the boolean value of.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n get(index: number) {\r\n return (this.buffer[index >> 3] >> (index & 7)) & 1 ? true : false;\r\n }\r\n\r\n /**\r\n * 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 * @param {number} index - The index to get the boolean value of.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n getSafe(index: number) {\r\n if (index < 0 || index >= this.size) {\r\n throw new RangeError(ERROR_OUT_OF_BOUNDS);\r\n }\r\n return this.get(index);\r\n }\r\n\r\n /**\r\n * Resizes the array to a new size, preserving existing data.\r\n * @param {number} newSize - The new size of the array.\r\n */\r\n resize(newSize: number) {\r\n const newBuffer = new Uint8Array(Math.ceil(newSize / 8));\r\n newBuffer.set(\r\n this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length))\r\n );\r\n this.size = newSize;\r\n this.buffer = newBuffer;\r\n }\r\n\r\n get length() {\r\n return this.size;\r\n }\r\n\r\n /**\r\n * Compares this FastBooleanArray with another for equality.\r\n * @param {FastBooleanArray} other - The other FastBooleanArray to compare.\r\n * @returns {boolean} True if both arrays are equal, false otherwise.\r\n */\r\n equals(other: FastBooleanArray) {\r\n if (this.size !== other.size) {\r\n return false;\r\n }\r\n return this.buffer.every((byte, i) => byte === other.buffer[i]);\r\n }\r\n\r\n /**\r\n * Makes the array iterable using `for...of`.\r\n */\r\n *[Symbol.iterator]() {\r\n for (let i = 0; i < this.size; i++) {\r\n yield this.get(i);\r\n }\r\n }\r\n\r\n /**\r\n * Converts to a standard JavaScript array.\r\n */\r\n toArray() {\r\n const arr = new Array(this.size);\r\n for (let i = 0; i < this.size; i++) {\r\n arr[i] = this.get(i);\r\n }\r\n return arr;\r\n }\r\n\r\n /**\r\n * Returns a proxy to the FastBooleanArray instance\r\n * With this you can access indexes like on an actual array.\r\n */\r\n accessLikeArray() {\r\n return new Proxy(this, {\r\n get: (target, prop) => {\r\n if (typeof prop === \"string\" && !isNaN(Number(prop))) {\r\n const index = Number(prop);\r\n return target.get(index);\r\n }\r\n return target[prop as keyof FastBooleanArray];\r\n },\r\n set: (target, prop, value) => {\r\n if (typeof prop === \"string\" && !isNaN(Number(prop))) {\r\n const index = Number(prop);\r\n target.set(index, value as never);\r\n } else {\r\n target[prop as Exclude<keyof FastBooleanArray, \"length\">] = value;\r\n }\r\n\r\n return true;\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * Applies a callback function to each element in the array.\r\n * @param {Function} callback - The function to execute on each element.\r\n */\r\n forEach(\r\n callback: (value: boolean, index: number, array: FastBooleanArray) => void\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n callback(this.get(i), i, this);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new array with the results of calling a provided function on every element.\r\n * @param {Function} callback - The function to execute on each element.\r\n */\r\n map(\r\n callback: (value: boolean, index: number, array: FastBooleanArray) => never\r\n ) {\r\n const result = new Array(this.size);\r\n for (let i = 0; i < this.size; i++) {\r\n result[i] = callback(this.get(i), i, this);\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new array with all elements that pass the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n filter(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => boolean\r\n ) {\r\n const result: boolean[] = [];\r\n for (let i = 0; i < this.size; i++) {\r\n const value = this.get(i);\r\n if (callback(value, i, this)) {\r\n result.push(value);\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Tests whether at least one element in the array passes the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n some(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => boolean\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n if (callback(this.get(i), i, this)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Tests whether all elements in the array pass the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n every(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => boolean\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n if (!callback(this.get(i), i, this)) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Reduces the array to a single value by applying a function to each element.\r\n * @param {Function} callback - The function to execute on each element.\r\n * @param {any} initialValue - The initial value for the accumulator.\r\n */\r\n reduce<T>(\r\n callback: (\r\n accumulator: T,\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => T,\r\n initialValue: T\r\n ): T {\r\n let accumulator = initialValue;\r\n for (let i = 0; i < this.size; i++) {\r\n accumulator = callback(accumulator, this.get(i), i, this);\r\n }\r\n return accumulator;\r\n }\r\n\r\n /**\r\n * Generates a string where every boolean is either a 0 or 1.\r\n */\r\n toString() {\r\n let result = ``;\r\n for (let i = 0; i < this.size; i++) {\r\n result += this.get(i) ? \"1\" : \"0\";\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from .toString() output\r\n */\r\n static fromString(value: string) {\r\n const array = new FastBooleanArray(value.length);\r\n for (let i = 0; i < value.length; i++) {\r\n array.set(i, value[i] == \"1\");\r\n }\r\n return array;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from a boolean array or number array\r\n */\r\n static fromArray(value: boolean[] | number[]) {\r\n const array = new FastBooleanArray(value.length);\r\n for (let i = 0; i < value.length; i++) {\r\n array.set(i, !!value[i]);\r\n }\r\n return array;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from a string, boolean array or number array\r\n */\r\n static from(value: string | boolean[] | number[]) {\r\n if (typeof value === \"string\") {\r\n return FastBooleanArray.fromString(value);\r\n }\r\n\r\n return FastBooleanArray.fromArray(value);\r\n }\r\n}\r\n"],"mappings":"4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAMI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OUNDS","_FastBooleanArray","size","index","value","newSize","newBuffer","other","byte","i","arr","target","prop","callback","result","initialValue","accumulator","array"]}
package/dist/index.d.cts DELETED
@@ -1,113 +0,0 @@
1
- declare class FastBooleanArray {
2
- size: number;
3
- private buffer;
4
- constructor(size: number);
5
- /**
6
- * Sets a boolean value at the specified index.
7
- * @param {number} index - The index to set the boolean value at.
8
- * @param {number} value - The boolean value to set the `index`.
9
- * @returns {boolean} The boolean value that was set.
10
- */
11
- set(index: number, value: boolean): boolean;
12
- /**
13
- * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
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
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
18
- */
19
- setSafe(index: number, value: boolean): boolean;
20
- /**
21
- * Sets all bits to the specified boolean value.
22
- * @param {boolean} value - The boolean value to set all bits to.
23
- */
24
- setAll(value: boolean): void;
25
- /**
26
- * Gets a boolean value at the specified index.
27
- * @param {number} index - The index to get the boolean value of.
28
- * @returns {boolean} The boolean value that was set.
29
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
30
- */
31
- get(index: number): boolean;
32
- /**
33
- * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
34
- * @param {number} index - The index to get the boolean value of.
35
- * @returns {boolean} The boolean value that was set.
36
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
37
- */
38
- getSafe(index: number): boolean;
39
- /**
40
- * Resizes the array to a new size, preserving existing data.
41
- * @param {number} newSize - The new size of the array.
42
- */
43
- resize(newSize: number): void;
44
- get length(): number;
45
- /**
46
- * Compares this FastBooleanArray with another for equality.
47
- * @param {FastBooleanArray} other - The other FastBooleanArray to compare.
48
- * @returns {boolean} True if both arrays are equal, false otherwise.
49
- */
50
- equals(other: FastBooleanArray): boolean;
51
- /**
52
- * Makes the array iterable using `for...of`.
53
- */
54
- [Symbol.iterator](): Generator<boolean, void, unknown>;
55
- /**
56
- * Converts to a standard JavaScript array.
57
- */
58
- toArray(): any[];
59
- /**
60
- * Returns a proxy to the FastBooleanArray instance
61
- * With this you can access indexes like on an actual array.
62
- */
63
- accessLikeArray(): this;
64
- /**
65
- * Applies a callback function to each element in the array.
66
- * @param {Function} callback - The function to execute on each element.
67
- */
68
- forEach(callback: (value: boolean, index: number, array: FastBooleanArray) => void): void;
69
- /**
70
- * Creates a new array with the results of calling a provided function on every element.
71
- * @param {Function} callback - The function to execute on each element.
72
- */
73
- map(callback: (value: boolean, index: number, array: FastBooleanArray) => never): any[];
74
- /**
75
- * Creates a new array with all elements that pass the test implemented by the provided function.
76
- * @param {Function} callback - The function to test each element.
77
- */
78
- filter(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean[];
79
- /**
80
- * Tests whether at least one element in the array passes the test implemented by the provided function.
81
- * @param {Function} callback - The function to test each element.
82
- */
83
- some(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean;
84
- /**
85
- * Tests whether all elements in the array pass the test implemented by the provided function.
86
- * @param {Function} callback - The function to test each element.
87
- */
88
- every(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean;
89
- /**
90
- * Reduces the array to a single value by applying a function to each element.
91
- * @param {Function} callback - The function to execute on each element.
92
- * @param {any} initialValue - The initial value for the accumulator.
93
- */
94
- reduce<T>(callback: (accumulator: T, value: boolean, index: number, array: FastBooleanArray) => T, initialValue: T): T;
95
- /**
96
- * Generates a string where every boolean is either a 0 or 1.
97
- */
98
- toString(): string;
99
- /**
100
- * Returns a FastBooleanArray from .toString() output
101
- */
102
- static fromString(value: string): FastBooleanArray;
103
- /**
104
- * Returns a FastBooleanArray from a boolean array or number array
105
- */
106
- static fromArray(value: boolean[] | number[]): FastBooleanArray;
107
- /**
108
- * Returns a FastBooleanArray from a string, boolean array or number array
109
- */
110
- static from(value: string | boolean[] | number[]): FastBooleanArray;
111
- }
112
-
113
- export { FastBooleanArray as default };
package/dist/index.d.ts DELETED
@@ -1,113 +0,0 @@
1
- declare class FastBooleanArray {
2
- size: number;
3
- private buffer;
4
- constructor(size: number);
5
- /**
6
- * Sets a boolean value at the specified index.
7
- * @param {number} index - The index to set the boolean value at.
8
- * @param {number} value - The boolean value to set the `index`.
9
- * @returns {boolean} The boolean value that was set.
10
- */
11
- set(index: number, value: boolean): boolean;
12
- /**
13
- * like `set` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
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
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
18
- */
19
- setSafe(index: number, value: boolean): boolean;
20
- /**
21
- * Sets all bits to the specified boolean value.
22
- * @param {boolean} value - The boolean value to set all bits to.
23
- */
24
- setAll(value: boolean): void;
25
- /**
26
- * Gets a boolean value at the specified index.
27
- * @param {number} index - The index to get the boolean value of.
28
- * @returns {boolean} The boolean value that was set.
29
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
30
- */
31
- get(index: number): boolean;
32
- /**
33
- * like `get` but throws if the index is out of bounds (less than 0 or greater than or equal to the array size).
34
- * @param {number} index - The index to get the boolean value of.
35
- * @returns {boolean} The boolean value that was set.
36
- * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).
37
- */
38
- getSafe(index: number): boolean;
39
- /**
40
- * Resizes the array to a new size, preserving existing data.
41
- * @param {number} newSize - The new size of the array.
42
- */
43
- resize(newSize: number): void;
44
- get length(): number;
45
- /**
46
- * Compares this FastBooleanArray with another for equality.
47
- * @param {FastBooleanArray} other - The other FastBooleanArray to compare.
48
- * @returns {boolean} True if both arrays are equal, false otherwise.
49
- */
50
- equals(other: FastBooleanArray): boolean;
51
- /**
52
- * Makes the array iterable using `for...of`.
53
- */
54
- [Symbol.iterator](): Generator<boolean, void, unknown>;
55
- /**
56
- * Converts to a standard JavaScript array.
57
- */
58
- toArray(): any[];
59
- /**
60
- * Returns a proxy to the FastBooleanArray instance
61
- * With this you can access indexes like on an actual array.
62
- */
63
- accessLikeArray(): this;
64
- /**
65
- * Applies a callback function to each element in the array.
66
- * @param {Function} callback - The function to execute on each element.
67
- */
68
- forEach(callback: (value: boolean, index: number, array: FastBooleanArray) => void): void;
69
- /**
70
- * Creates a new array with the results of calling a provided function on every element.
71
- * @param {Function} callback - The function to execute on each element.
72
- */
73
- map(callback: (value: boolean, index: number, array: FastBooleanArray) => never): any[];
74
- /**
75
- * Creates a new array with all elements that pass the test implemented by the provided function.
76
- * @param {Function} callback - The function to test each element.
77
- */
78
- filter(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean[];
79
- /**
80
- * Tests whether at least one element in the array passes the test implemented by the provided function.
81
- * @param {Function} callback - The function to test each element.
82
- */
83
- some(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean;
84
- /**
85
- * Tests whether all elements in the array pass the test implemented by the provided function.
86
- * @param {Function} callback - The function to test each element.
87
- */
88
- every(callback: (value: boolean, index: number, array: FastBooleanArray) => boolean): boolean;
89
- /**
90
- * Reduces the array to a single value by applying a function to each element.
91
- * @param {Function} callback - The function to execute on each element.
92
- * @param {any} initialValue - The initial value for the accumulator.
93
- */
94
- reduce<T>(callback: (accumulator: T, value: boolean, index: number, array: FastBooleanArray) => T, initialValue: T): T;
95
- /**
96
- * Generates a string where every boolean is either a 0 or 1.
97
- */
98
- toString(): string;
99
- /**
100
- * Returns a FastBooleanArray from .toString() output
101
- */
102
- static fromString(value: string): FastBooleanArray;
103
- /**
104
- * Returns a FastBooleanArray from a boolean array or number array
105
- */
106
- static fromArray(value: boolean[] | number[]): FastBooleanArray;
107
- /**
108
- * Returns a FastBooleanArray from a string, boolean array or number array
109
- */
110
- static from(value: string | boolean[] | number[]): FastBooleanArray;
111
- }
112
-
113
- export { FastBooleanArray as default };
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- var a="Index out of bounds",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(a);return this.set(e,r)}setAll(e){this.buffer.fill(e?255:0)}get(e){return!!(this.buffer[e>>3]>>(e&7)&1)}getSafe(e){if(e<0||e>=this.size)throw new RangeError(a);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.size=e,this.buffer=r}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);e.set(s,t)}else e[r]=t;return!0}})}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};
2
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["const ERROR_OUT_OF_BOUNDS = \"Index out of bounds\";\r\n\r\nexport default class FastBooleanArray {\r\n public size: number;\r\n private buffer: Uint8Array;\r\n\r\n constructor(size: number) {\r\n if (!size) {\r\n throw new Error(\"FastBooleanArray must have a size greater than 0\");\r\n }\r\n this.size = size;\r\n this.buffer = new Uint8Array(Math.ceil(size / 8)); // Allocate memory\r\n }\r\n\r\n /**\r\n * Sets a boolean value at the specified index.\r\n * @param {number} index - The index to set the boolean value at.\r\n * @param {number} value - The boolean value to set the `index`.\r\n * @returns {boolean} The boolean value that was set.\r\n */\r\n set(index: number, value: boolean) {\r\n if (value) {\r\n this.buffer[index >> 3] |= 1 << (index & 7); // Set bit\r\n return true;\r\n } else {\r\n this.buffer[index >> 3] &= ~(1 << (index & 7)); // Clear bit\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * 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 * @param {number} index - The index to set the boolean value at.\r\n * @param {number} value - The boolean value to set the `index`.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n setSafe(index: number, value: boolean) {\r\n if (index < 0 || index >= this.size) {\r\n throw new RangeError(ERROR_OUT_OF_BOUNDS);\r\n }\r\n return this.set(index, value);\r\n }\r\n\r\n /**\r\n * Sets all bits to the specified boolean value.\r\n * @param {boolean} value - The boolean value to set all bits to.\r\n */\r\n setAll(value: boolean) {\r\n this.buffer.fill(value ? 0xff : 0x00);\r\n }\r\n\r\n /**\r\n * Gets a boolean value at the specified index.\r\n * @param {number} index - The index to get the boolean value of.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n get(index: number) {\r\n return (this.buffer[index >> 3] >> (index & 7)) & 1 ? true : false;\r\n }\r\n\r\n /**\r\n * 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 * @param {number} index - The index to get the boolean value of.\r\n * @returns {boolean} The boolean value that was set.\r\n * @throws {RangeError} If the index is out of bounds (less than 0 or greater than or equal to the array size).\r\n */\r\n getSafe(index: number) {\r\n if (index < 0 || index >= this.size) {\r\n throw new RangeError(ERROR_OUT_OF_BOUNDS);\r\n }\r\n return this.get(index);\r\n }\r\n\r\n /**\r\n * Resizes the array to a new size, preserving existing data.\r\n * @param {number} newSize - The new size of the array.\r\n */\r\n resize(newSize: number) {\r\n const newBuffer = new Uint8Array(Math.ceil(newSize / 8));\r\n newBuffer.set(\r\n this.buffer.subarray(0, Math.min(this.buffer.length, newBuffer.length))\r\n );\r\n this.size = newSize;\r\n this.buffer = newBuffer;\r\n }\r\n\r\n get length() {\r\n return this.size;\r\n }\r\n\r\n /**\r\n * Compares this FastBooleanArray with another for equality.\r\n * @param {FastBooleanArray} other - The other FastBooleanArray to compare.\r\n * @returns {boolean} True if both arrays are equal, false otherwise.\r\n */\r\n equals(other: FastBooleanArray) {\r\n if (this.size !== other.size) {\r\n return false;\r\n }\r\n return this.buffer.every((byte, i) => byte === other.buffer[i]);\r\n }\r\n\r\n /**\r\n * Makes the array iterable using `for...of`.\r\n */\r\n *[Symbol.iterator]() {\r\n for (let i = 0; i < this.size; i++) {\r\n yield this.get(i);\r\n }\r\n }\r\n\r\n /**\r\n * Converts to a standard JavaScript array.\r\n */\r\n toArray() {\r\n const arr = new Array(this.size);\r\n for (let i = 0; i < this.size; i++) {\r\n arr[i] = this.get(i);\r\n }\r\n return arr;\r\n }\r\n\r\n /**\r\n * Returns a proxy to the FastBooleanArray instance\r\n * With this you can access indexes like on an actual array.\r\n */\r\n accessLikeArray() {\r\n return new Proxy(this, {\r\n get: (target, prop) => {\r\n if (typeof prop === \"string\" && !isNaN(Number(prop))) {\r\n const index = Number(prop);\r\n return target.get(index);\r\n }\r\n return target[prop as keyof FastBooleanArray];\r\n },\r\n set: (target, prop, value) => {\r\n if (typeof prop === \"string\" && !isNaN(Number(prop))) {\r\n const index = Number(prop);\r\n target.set(index, value as never);\r\n } else {\r\n target[prop as Exclude<keyof FastBooleanArray, \"length\">] = value;\r\n }\r\n\r\n return true;\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * Applies a callback function to each element in the array.\r\n * @param {Function} callback - The function to execute on each element.\r\n */\r\n forEach(\r\n callback: (value: boolean, index: number, array: FastBooleanArray) => void\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n callback(this.get(i), i, this);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new array with the results of calling a provided function on every element.\r\n * @param {Function} callback - The function to execute on each element.\r\n */\r\n map(\r\n callback: (value: boolean, index: number, array: FastBooleanArray) => never\r\n ) {\r\n const result = new Array(this.size);\r\n for (let i = 0; i < this.size; i++) {\r\n result[i] = callback(this.get(i), i, this);\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Creates a new array with all elements that pass the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n filter(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => boolean\r\n ) {\r\n const result: boolean[] = [];\r\n for (let i = 0; i < this.size; i++) {\r\n const value = this.get(i);\r\n if (callback(value, i, this)) {\r\n result.push(value);\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Tests whether at least one element in the array passes the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n some(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => boolean\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n if (callback(this.get(i), i, this)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Tests whether all elements in the array pass the test implemented by the provided function.\r\n * @param {Function} callback - The function to test each element.\r\n */\r\n every(\r\n callback: (\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => boolean\r\n ) {\r\n for (let i = 0; i < this.size; i++) {\r\n if (!callback(this.get(i), i, this)) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Reduces the array to a single value by applying a function to each element.\r\n * @param {Function} callback - The function to execute on each element.\r\n * @param {any} initialValue - The initial value for the accumulator.\r\n */\r\n reduce<T>(\r\n callback: (\r\n accumulator: T,\r\n value: boolean,\r\n index: number,\r\n array: FastBooleanArray\r\n ) => T,\r\n initialValue: T\r\n ): T {\r\n let accumulator = initialValue;\r\n for (let i = 0; i < this.size; i++) {\r\n accumulator = callback(accumulator, this.get(i), i, this);\r\n }\r\n return accumulator;\r\n }\r\n\r\n /**\r\n * Generates a string where every boolean is either a 0 or 1.\r\n */\r\n toString() {\r\n let result = ``;\r\n for (let i = 0; i < this.size; i++) {\r\n result += this.get(i) ? \"1\" : \"0\";\r\n }\r\n return result;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from .toString() output\r\n */\r\n static fromString(value: string) {\r\n const array = new FastBooleanArray(value.length);\r\n for (let i = 0; i < value.length; i++) {\r\n array.set(i, value[i] == \"1\");\r\n }\r\n return array;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from a boolean array or number array\r\n */\r\n static fromArray(value: boolean[] | number[]) {\r\n const array = new FastBooleanArray(value.length);\r\n for (let i = 0; i < value.length; i++) {\r\n array.set(i, !!value[i]);\r\n }\r\n return array;\r\n }\r\n\r\n /**\r\n * Returns a FastBooleanArray from a string, boolean array or number array\r\n */\r\n static from(value: string | boolean[] | number[]) {\r\n if (typeof value === \"string\") {\r\n return FastBooleanArray.fromString(value);\r\n }\r\n\r\n return FastBooleanArray.fromArray(value);\r\n }\r\n}\r\n"],"mappings":"AAAA,IAAMA,EAAsB,sBAEPC,E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","other","byte","i","arr","target","prop","callback","result","initialValue","accumulator","array"]}