### Installation and Testing Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Instructions for installing the library and running tests. ```APIDOC ## Installation ### Description Installs the `typedfastbitset` package using npm. ### Method npm install ### Endpoint `npm install typedfastbitset` ### Parameters None ### Request Example ```bash npm install typedfastbitset ``` ## Testing ### Description Runs the test suite for the `typedfastbitset` library using npm. ### Method npm test ### Endpoint `npm test` ### Parameters None ### Request Example ```bash npm test ``` ``` -------------------------------- ### Install Dependencies and Run Benchmarks Source: https://github.com/lemire/typedfastbitset.js/blob/master/benchmark/README.md Installs necessary benchmarking packages and runs the benchmark tests. Use `--no-save` for Node.js 5.0.0 and above. ```bash npm install --no-save benchmark microtime bitset.js fastbitset fast-bitset roaring nodejs test.js ``` -------------------------------- ### Install Benchmark Dependencies Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Install necessary npm packages for running the benchmarks. This includes benchmark tools and various bitset libraries. ```bash npm install benchmark fastbitset bitset bitset.js fast-bitset roaring minimist ``` -------------------------------- ### Install TypedFastBitSet Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Install the typedfastbitset package using npm. ```bash npm install typedfastbitset ``` -------------------------------- ### Using SparseTypedFastBitSet for Sparse Data Source: https://context7.com/lemire/typedfastbitset.js/llms.txt SparseTypedFastBitSet is optimized for sparse data, starting as an array and converting to a bitset when beneficial. It supports all operations of TypedFastBitSet and efficiently performs set operations. ```javascript const { SparseTypedFastBitSet } = require("typedfastbitset"); // Ideal for sparse data with scattered values const sparse = new SparseTypedFastBitSet([100, 500, 1000, 5000, 10000]); console.log(sparse.size()); // Output: 5 // Supports all the same operations as TypedFastBitSet sparse.add(200); sparse.remove(500); console.log(sparse.array()); // Output: [100, 200, 1000, 5000, 10000] // Performs set operations efficiently const other = new SparseTypedFastBitSet([100, 200, 300]); const intersection = sparse.new_intersection(other); console.log(intersection.array()); // Output: [100, 200] // Automatically optimizes internal storage sparse.trim(); // Reduces memory to minimum required ``` -------------------------------- ### Build and Run Benchmarks Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Build the package and execute the benchmark suite. This will generate performance metrics for different bitset operations. ```bash npm run build:package npm run benchmark ``` -------------------------------- ### Create TypedFastBitSet Instances Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Demonstrates creating a TypedFastBitSet from scratch, from an array of values, or from a raw Uint32Array. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); // Create an empty bitset const empty = new TypedFastBitSet(); // Create a bitset from an array of values const bitset = new TypedFastBitSet([1, 5, 10, 100, 1000]); console.log(bitset.toString()); // Output: {1,5,10,100,1000} console.log(bitset.size()); // Output: 5 ``` ```javascript // Create from raw word array const words = new Uint32Array([0b1010, 0b0101]); const fromWords = TypedFastBitSet.fromWords(words); console.log(fromWords.array()); // Output: [1, 3, 32, 34] ``` -------------------------------- ### Constructor and Static Methods Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Details on how to create new TypedFastBitSet instances and static methods available. ```APIDOC ## Constructor and Static Methods ### `new TypedFastBitSet(iterable?)` **Description**: Creates a new BitSet instance. It can be optionally initialized with an iterable of integers. ### `TypedFastBitSet.fromWords(words: Uint32Array)` **Description**: Creates a new BitSet instance directly from a raw Uint32Array of words. ``` -------------------------------- ### Initialize and Use TypedFastBitSet Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Demonstrates basic usage including initialization, adding elements, checking for presence, and string representation. Use this for general set management with integers. ```javascript const b = new TypedFastBitSet(); // initially empty b.add(1); // add the value "1" b.has(1); // check that the value is present! (will return true) b.add(2); console.log("" + b); // should display {1,2} b.add(10); b.addRange(11, 13); b.array(); // would return [1, 2, 10, 11, 12, 13] let c = new TypedFastBitSet([1, 2, 3, 10]); // create bitset initialized with values 1,2,3,10 ``` -------------------------------- ### Comparison and Utility Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Methods for comparing bitmaps, creating copies, managing memory, and string representation. ```APIDOC ## equals(other) ### Description Returns `true` if the current bitmap and the `other` bitmap contain the exact same set bits, `false` otherwise. ### Method `equals` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to compare with. ### Request Example ```json { "example": "bitmap1.equals(bitmap2)" } ``` ### Response #### Success Response (200) - **boolean** - `true` if the bitmaps are equal, `false` otherwise. #### Response Example ```json { "example": "true" } ``` ## intersects(other) ### Description Returns `true` if the current bitmap and the `other` bitmap share at least one common set bit, `false` otherwise. ### Method `intersects` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to check for intersection with. ### Request Example ```json { "example": "bitmap1.intersects(bitmap2)" } ``` ### Response #### Success Response (200) - **boolean** - `true` if the bitmaps intersect, `false` otherwise. #### Response Example ```json { "example": "true" } ``` ## clone() ### Description Returns a deep copy of the current bitmap. ### Method `clone` ### Parameters None ### Request Example ```json { "example": "bitmap.clone()" } ``` ### Response #### Success Response (200) - **TypedFastBitSet** - A new bitmap that is a deep copy of the original. #### Response Example ```json { "example": "clonedBitmap" } ``` ## trim() ### Description Reduces the memory usage of the bitmap by removing any trailing unused memory words (bits set to 0). ### Method `trim` ### Parameters None ### Request Example ```json { "example": "bitmap.trim()" } ``` ### Response #### Success Response (200) This method modifies the bitmap in place and does not return a value. ## resize(index) ### Description Ensures that the bitmap has enough capacity to hold bits up to the given `index`. This may result in over-allocation for performance reasons. ### Method `resize` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **index** (number) - Required - The maximum index (inclusive) that the bitmap should be able to hold. ### Request Example ```json { "example": "bitmap.resize(1000)" } ``` ### Response #### Success Response (200) This method modifies the bitmap in place and does not return a value. ## resizeTo(size) ### Description Ensures that the bitmap has capacity for exactly `size` bits, without over-allocation. ### Method `resizeTo` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **size** (number) - Required - The exact number of bits the bitmap should accommodate. ### Request Example ```json { "example": "bitmap.resizeTo(500)" } ``` ### Response #### Success Response (200) This method modifies the bitmap in place and does not return a value. ## toString() ### Description Returns a string representation of the bitmap, typically in a format like `{1,2,3}`. ### Method `toString` ### Parameters None ### Request Example ```json { "example": "bitmap.toString()" } ``` ### Response #### Success Response (200) - **string** - The string representation of the bitmap. #### Response Example ```json { "example": "{1,2,3}" } ``` ``` -------------------------------- ### Run Tests for typedfastbitset.js Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Execute the test suite for typedfastbitset.js using npm. This command runs the predefined tests to ensure the library is functioning correctly. ```bash npm test ``` -------------------------------- ### Comparison and Cloning Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Methods for comparing bitsets for equality and creating deep copies. ```APIDOC ## Comparison and Cloning ### Description Provides methods to compare bitsets for equality and to create independent copies. The `equals()` method checks if two bitsets contain the exact same elements. The `clone()` method creates a deep copy of a bitset, ensuring that modifications to the clone do not affect the original. ### Methods #### `equals(other: TypedFastBitSet): boolean` Compares the current bitset with another bitset for equality. Returns `true` if both bitsets contain the same elements, `false` otherwise. #### `clone(): TypedFastBitSet` Creates and returns a deep copy (clone) of the current bitset. #### `toString(): string` Returns a string representation of the bitset, typically in the format `{element1,element2,...}`. ### Request Example ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3]); const b = new TypedFastBitSet([1, 2, 3]); const c = new TypedFastBitSet([1, 2, 4]); // Check equality console.log(a.equals(b)); // Output: true console.log(a.equals(c)); // Output: false // Clone a bitset (deep copy) const cloned = a.clone(); cloned.add(100); console.log(a.array()); // Output: [1, 2, 3] (original unchanged) console.log(cloned.array()); // Output: [1, 2, 3, 100] // String representation console.log(a.toString()); // Output: {1,2,3} ``` ``` -------------------------------- ### Cloning and Equality Check for TypedFastBitSet Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Shows how to create a deep copy of a bitset and how to check if two bitsets are identical. Useful for preserving state or comparing sets. ```javascript c = b.clone(); // create a (deep) copy of b and assign it to c. c.equals(b); // checks whether c and b are equal ``` -------------------------------- ### BitSet Comparison and Cloning Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Use `equals()` to compare two bitsets for equality. `clone()` creates a deep copy of a bitset. `toString()` provides a string representation. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3]); const b = new TypedFastBitSet([1, 2, 3]); const c = new TypedFastBitSet([1, 2, 4]); // Check equality console.log(a.equals(b)); // Output: true console.log(a.equals(c)); // Output: false // Clone a bitset (deep copy) const cloned = a.clone(); cloned.add(100); console.log(a.array()); // Output: [1, 2, 3] (original unchanged) console.log(cloned.array()); // Output: [1, 2, 3, 100] // String representation console.log(a.toString()); // Output: {1,2,3} ``` -------------------------------- ### Memory Management with TypedFastBitSet Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Use `trim()` to reduce memory usage by removing unused capacity, and `resize()`/`resizeTo()` to pre-allocate capacity for known sizes. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const bitset = new TypedFastBitSet(); // Add some large values (causes internal buffer growth) bitset.add(10000); bitset.add(10001); bitset.add(10002); // Remove values bitset.remove(10000); bitset.remove(10001); bitset.remove(10002); // Trim unused memory bitset.trim(); // Pre-allocate for known capacity const preallocated = new TypedFastBitSet(); preallocated.resize(1000); // Ensure capacity for index 1000 preallocated.resizeTo(2000); // Exact allocation for 2000 bits ``` -------------------------------- ### Importing TypedFastBitSet in Node.js Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Shows the necessary import statement for using TypedFastBitSet in a Node.js environment. This is required before instantiating the class. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const b = new TypedFastBitSet(); // initially empty b.add(1); // add the value "1" ``` -------------------------------- ### Iterating over TypedFastBitSet Elements Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Demonstrates how to iterate over the elements within a bitset using `forEach` or the `for...of` loop. The `for...of` loop allows for early exit using `break`. ```javascript c.forEach(fnc); // execute fnc on each value stored in c for (const x of c) fnc(x); // execute fnc on each value stored in c (allows early exit with break) ``` -------------------------------- ### Size Queries Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Methods for querying the size or state of the bitmap without modifying it. ```APIDOC ## size() ### Description Returns the number of set bits (bits with value 1) in the bitmap. ### Method `size` ### Parameters None ### Request Example ```json { "example": "bitmap.size()" } ``` ### Response #### Success Response (200) - **number** - The count of set bits. #### Response Example ```json { "example": "123" } ``` ## isEmpty() ### Description Returns `true` if the bitmap contains no set bits, `false` otherwise. ### Method `isEmpty` ### Parameters None ### Request Example ```json { "example": "bitmap.isEmpty()" } ``` ### Response #### Success Response (200) - **boolean** - `true` if the bitmap is empty, `false` otherwise. #### Response Example ```json { "example": "true" } ``` ## union_size(other) ### Description Returns the size of the union between the current bitmap and the `other` bitmap without creating a new bitmap. ### Method `union_size` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to compute the union size with. ### Request Example ```json { "example": "bitmap1.union_size(bitmap2)" } ``` ### Response #### Success Response (200) - **number** - The number of set bits in the union. #### Response Example ```json { "example": "456" } ``` ## intersection_size(other) ### Description Returns the size of the intersection between the current bitmap and the `other` bitmap without creating a new bitmap. ### Method `intersection_size` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to compute the intersection size with. ### Request Example ```json { "example": "bitmap1.intersection_size(bitmap2)" } ``` ### Response #### Success Response (200) - **number** - The number of set bits in the intersection. #### Response Example ```json { "example": "78" } ``` ## difference_size(other) ### Description Returns the size of the difference (`this & ~other`) between the current bitmap and the `other` bitmap without creating a new bitmap. ### Method `difference_size` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to compute the difference size with. ### Request Example ```json { "example": "bitmap1.difference_size(bitmap2)" } ``` ### Response #### Success Response (200) - **number** - The number of set bits in the difference. #### Response Example ```json { "example": "90" } ``` ## change_size(other) ### Description Returns the size of the symmetric difference (change) between the current bitmap and the `other` bitmap without creating a new bitmap. ### Method `change_size` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to compute the symmetric difference size with. ### Request Example ```json { "example": "bitmap1.change_size(bitmap2)" } ``` ### Response #### Success Response (200) - **number** - The number of set bits in the symmetric difference. #### Response Example ```json { "example": "12" } ``` ``` -------------------------------- ### Set Operations with TypedFastBitSet Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Illustrates various set operations like difference, change, union, and intersection. These operations can modify the existing bitset in-place for performance. ```javascript c.difference(b); // from c, remove elements that are in b (modifies c) c.difference2(b); // from c, remove elements that are in b (modifies b) c.change(b); // c will contain all elements that are in b or in c, but not both (elements that changed) const su = c.union_size(b); // compute the size of the union (bitsets are unchanged) c.union(b); // c will contain all elements that are in c and b const out1 = c.new_union(b); // creates a new bitmap that contains everything in c and b const out2 = c.new_intersection(b); // creates a new bitmap that contains everything that is in both c and b const out3 = c.new_change(b); // creates a new bitmap that contains everything in b or in c, but not both const s1 = c.intersection_size(b); // compute the size of the intersection (bitsets are unchanged) const s2 = c.difference_size(b); // compute the size of the difference (bitsets are unchanged) const s3 = c.change_size(b); // compute the number of elements that are in b but not c, or vice versa c.intersects(b); // return true if c intersects with b c.intersection(b); // c will only contain elements that are in both c and b ``` -------------------------------- ### Set Operations (new instance) Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Set operations that return a new BitSet instance without modifying the original ones. ```APIDOC ## Set Operations (new instance) ### `new_union(other)` **Description**: Returns a new BitSet containing all elements that are in either the current BitSet or the `other` BitSet. The original BitSets are unchanged. ### `new_intersection(other)` **Description**: Returns a new BitSet containing only elements that are present in both the current BitSet and the `other` BitSet. The original BitSets are unchanged. ### `new_difference(other)` **Description**: Returns a new BitSet containing elements that are in the current BitSet but not in the `other` BitSet. The original BitSets are unchanged. ### `new_change(other)` **Description**: Returns a new BitSet containing elements that are in either the current BitSet or the `other` BitSet, but not in both (symmetric difference). The original BitSets are unchanged. ``` -------------------------------- ### Iteration and Enumeration Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Methods for iterating over the elements of a bitset and retrieving its size. ```APIDOC ## Iteration and Enumeration ### Description BitSets support multiple methods for iterating through their elements and retrieving the total count of set bits. `array()` returns all values as an array, `forEach()` executes a provided function once for each element, and the built-in iterator allows the use of `for...of` loops. `size()` returns the number of set bits. ### Methods #### `array(): number[]` Returns an array containing all the elements currently set in the bitset. #### `forEach(callbackFn: (value: number) => void): void` Executes a `callbackFn` function for each element in the bitset. #### `size(): number` Returns the total number of set bits (elements) in the bitset. ### Request Example ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const bitset = new TypedFastBitSet([5, 10, 15, 20, 25]); // Get all values as an array const values = bitset.array(); console.log(values); // Output: [5, 10, 15, 20, 25] // Iterate with forEach const doubled = []; bitset.forEach((value) => { doubled.push(value * 2); }); console.log(doubled); // Output: [10, 20, 30, 40, 50] // Use for...of loop (supports early exit with break) let sum = 0; for (const value of bitset) { sum += value; if (sum > 30) break; } console.log(sum); // Output: 35 (5 + 10 + 15 + ... stopped early) // Get the count of set bits console.log(bitset.size()); // Output: 5 ``` ``` -------------------------------- ### Size and Comparison Operations Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Methods for calculating sizes of set operations and comparing BitSets. ```APIDOC ## Size and Comparison Operations ### `union_size(other)` **Description**: Computes and returns the size (number of set bits) of the union of the current BitSet and the `other` BitSet. The BitSets are not modified. ### `intersection_size(other)` **Description**: Computes and returns the size (number of set bits) of the intersection of the current BitSet and the `other` BitSet. The BitSets are not modified. ### `difference_size(other)` **Description**: Computes and returns the size (number of set bits) of the difference between the current BitSet and the `other` BitSet (elements in `this` but not in `other`). The BitSets are not modified. ### `change_size(other)` **Description**: Computes and returns the number of elements that are in either the current BitSet or the `other` BitSet, but not both (symmetric difference size). The BitSets are not modified. ### `intersects(other)` **Description**: Returns `true` if the current BitSet and the `other` BitSet have at least one common element (i.e., their intersection is not empty), otherwise returns `false`. ### `intersection(other)` **Description**: Updates the current BitSet to contain only elements that are present in both the current BitSet and the `other` BitSet (`this = this & other`). ### `clone()` **Description**: Creates and returns a deep copy (clone) of the current BitSet. ### `equals(other)` **Description**: Returns `true` if the current BitSet contains exactly the same elements as the `other` BitSet, otherwise returns `false`. ``` -------------------------------- ### Iteration Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Methods for iterating over the set bits in the BitSet. ```APIDOC ## Iteration ### `array()` **Description**: Returns an array containing all the indices of the set bits. ### `forEach(fn)` **Description**: Executes the provided function `fn` once for each set bit index. ### `[Symbol.iterator]()` **Description**: Returns an iterator that allows iterating over the set bit indices using `for...of` loops. Supports early exit with `break`. ``` -------------------------------- ### Basic Operations Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Core methods for manipulating individual bits within the BitSet. ```APIDOC ## Basic Operations ### `add(index)` **Description**: Sets the bit at the specified `index` to `true`. ### `checkedAdd(index)` **Description**: Adds the value at `index`. Returns `1` if the value was added, and `0` if it was already present. ### `remove(index)` **Description**: Sets the bit at the specified `index` to `false`. ### `flip(index)` **Description**: Toggles the bit at the specified `index` (from `true` to `false` or `false` to `true`). ### `has(index)` **Description**: Returns `true` if the bit at the specified `index` is set (`true`), otherwise returns `false`. ### `clear()` **Description**: Removes all values from the BitSet and resets its memory usage. ``` -------------------------------- ### Set Difference Methods Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Methods for computing the difference between two bitsets. ```APIDOC ## Set Difference ### Description Methods for computing the set difference between two bitsets. The `difference()` method removes elements from the current bitset that are present in another bitset (in-place). `difference2()` computes A - B and stores the result in the second bitset. `new_difference()` creates and returns a new bitset representing the difference. ### Methods #### `difference_size(other: TypedFastBitSet): number` Returns the number of elements in the current bitset that are not in the `other` bitset, without modifying either bitset. #### `new_difference(other: TypedFastBitSet): TypedFastBitSet` Creates and returns a new bitset containing elements that are in the current bitset but not in the `other` bitset (A - B). #### `difference(other: TypedFastBitSet): void` Removes elements from the current bitset that are also present in the `other` bitset (in-place modification). #### `difference2(other: TypedFastBitSet): void` Computes the difference of the current bitset (A) and the `other` bitset (B), storing the result (A - B) back into the `other` bitset. ### Request Example ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3, 4, 5]); const b = new TypedFastBitSet([3, 4, 5, 6, 7]); // Get difference size (a - b) const diffSize = a.difference_size(b); console.log(diffSize); // Output: 2 (elements 1 and 2) // Create new bitset with difference (a - b) const diffResult = a.new_difference(b); console.log(diffResult.array()); // Output: [1, 2] // In-place difference: removes from 'c' elements that are in 'd' const c = new TypedFastBitSet([1, 2, 3, 4, 5]); const d = new TypedFastBitSet([2, 4]); c.difference(d); console.log(c.array()); // Output: [1, 3, 5] // difference2: computes A - B and stores result in B const e = new TypedFastBitSet([1, 2, 3, 4, 5]); const f = new TypedFastBitSet([3, 4]); e.difference2(f); // f now contains elements in e but not originally in f console.log(f.array()); // Output: [1, 2, 5] ``` ``` -------------------------------- ### Add, Remove, and Flip Values in TypedFastBitSet Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Shows how to add, remove, toggle (flip), and check for the presence of individual values in a TypedFastBitSet. Use `checkedAdd` to determine if a value was newly added. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const bitset = new TypedFastBitSet(); // Add individual values bitset.add(5); bitset.add(10); bitset.add(15); console.log(bitset.has(10)); // Output: true console.log(bitset.has(7)); // Output: false // Remove a value bitset.remove(10); console.log(bitset.has(10)); // Output: false // Flip a bit (toggle) bitset.flip(20); // Adds 20 (was not present) bitset.flip(5); // Removes 5 (was present) console.log(bitset.array()); // Output: [15, 20] // Checked add returns 1 if added, 0 if already present const wasAdded1 = bitset.checkedAdd(25); // Returns 1 const wasAdded2 = bitset.checkedAdd(25); // Returns 0 console.log(wasAdded1, wasAdded2); // Output: 1 0 // Clear all values bitset.clear(); console.log(bitset.isEmpty()); // Output: true ``` -------------------------------- ### Symmetric Difference (XOR/Change) Methods Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Methods for computing the symmetric difference of two bitsets. ```APIDOC ## Symmetric Difference (XOR/Change) ### Description Computes the symmetric difference between two bitsets, which includes elements present in either bitset but not in both. The `change()` method performs this operation in-place. `new_change()` creates a new bitset with the result, and `change_size()` returns the count of elements in the symmetric difference. ### Methods #### `change_size(other: TypedFastBitSet): number` Returns the number of elements in the symmetric difference of the current bitset and another bitset. #### `new_change(other: TypedFastBitSet): TypedFastBitSet` Creates and returns a new bitset representing the symmetric difference of the current bitset and another bitset. #### `change(other: TypedFastBitSet): void` Computes the symmetric difference of the current bitset and another bitset in-place, modifying the current bitset. ### Request Example ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3, 4]); const b = new TypedFastBitSet([3, 4, 5, 6]); // Get symmetric difference size const changeSize = a.change_size(b); console.log(changeSize); // Output: 4 (elements 1, 2, 5, 6) // Create new bitset with symmetric difference const changeResult = a.new_change(b); console.log(changeResult.array()); // Output: [1, 2, 5, 6] // In-place symmetric difference const c = new TypedFastBitSet([1, 2, 3]); const d = new TypedFastBitSet([2, 3, 4]); c.change(d); console.log(c.array()); // Output: [1, 4] ``` ``` -------------------------------- ### Memory Optimization for TypedFastBitSet Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md The `trim()` method can be used to reduce the memory footprint of a bitset without altering its contents. Call this after significant modifications if memory usage is a concern. ```javascript c.trim(); // reduce the memory usage of the bitmap if possible, the content remains the same ``` -------------------------------- ### BitSet Iteration and Enumeration Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Iterate over bitset elements using `array()`, `forEach()`, or a `for...of` loop. `size()` returns the count of set bits. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const bitset = new TypedFastBitSet([5, 10, 15, 20, 25]); // Get all values as an array const values = bitset.array(); console.log(values); // Output: [5, 10, 15, 20, 25] // Iterate with forEach const doubled = []; bitset.forEach((value) => { doubled.push(value * 2); }); console.log(doubled); // Output: [10, 20, 30, 40, 50] // Use for...of loop (supports early exit with break) let sum = 0; for (const value of bitset) { sum += value; if (sum > 30) break; } console.log(sum); // Output: 35 (5 + 10 + 15 + ... stopped early) // Get the count of set bits console.log(bitset.size()); // Output: 5 ``` -------------------------------- ### Set Operations (in-place) Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md In-place set operations that modify the current BitSet instance. ```APIDOC ## Set Operations (in-place, modifies `this`) ### `union(other)` **Description**: Updates the current BitSet to contain all elements that are in either the current BitSet or the `other` BitSet (`this = this | other`). ### `intersection(other)` **Description**: Updates the current BitSet to contain only elements that are present in both the current BitSet and the `other` BitSet (`this = this & other`). ### `difference(other)` **Description**: Updates the current BitSet to contain elements that are in the current BitSet but not in the `other` BitSet (`this = this & ~other`). ### `difference2(other)` **Description**: Updates the `other` BitSet to contain elements that are in the current BitSet but not in the `other` BitSet (`other = this & ~other`). This operation modifies the `other` BitSet. ### `change(other)` **Description**: Updates the current BitSet to contain elements that are in either the current BitSet or the `other` BitSet, but not in both (symmetric difference) (`this = this ^ other`). ``` -------------------------------- ### Set Intersection Methods Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Methods for computing the intersection of two bitsets. ```APIDOC ## Set Intersection ### Description Computes the intersection of two bitsets. The `intersection()` method modifies the current bitset in-place, `new_intersection()` creates and returns a new bitset containing the intersection, and `intersects()` checks if two bitsets share any common values without modifying them. ### Methods #### `intersects(other: TypedFastBitSet): boolean` Checks if the current bitset shares any common elements with another bitset. #### `intersection_size(other: TypedFastBitSet): number` Returns the number of common elements between the current bitset and another bitset without creating a new bitset. #### `new_intersection(other: TypedFastBitSet): TypedFastBitSet` Creates and returns a new bitset that is the result of the intersection of the current bitset and another bitset. #### `intersection(other: TypedFastBitSet): void` Computes the intersection of the current bitset with another bitset in-place, modifying the current bitset. ### Request Example ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3, 4, 5]); const b = new TypedFastBitSet([3, 4, 5, 6, 7]); // Check if bitsets intersect console.log(a.intersects(b)); // Output: true // Get intersection size const intersectionSize = a.intersection_size(b); console.log(intersectionSize); // Output: 3 // Create new bitset containing intersection const intersectionResult = a.new_intersection(b); console.log(intersectionResult.array()); // Output: [3, 4, 5] // In-place intersection const c = new TypedFastBitSet([1, 2, 3, 4, 5]); const d = new TypedFastBitSet([2, 4, 6]); c.intersection(d); console.log(c.array()); // Output: [2, 4] ``` ``` -------------------------------- ### Memory Optimization Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Method for reducing memory usage. ```APIDOC ## Memory Optimization ### `trim()` **Description**: Reduces the memory usage of the BitSet if possible, without changing its content. This operation can be useful after many removals to reclaim unused memory. ``` -------------------------------- ### Range Operations Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Methods for efficiently operating on ranges of bits. ```APIDOC ## Range Operations ### `addRange(start, end)` **Description**: Sets all bits in the range from `start` (inclusive) to `end` (exclusive) to `true`. ### `removeRange(start, end)` **Description**: Clears all bits in the range from `start` (inclusive) to `end` (exclusive) to `false`. ### `hasAnyInRange(start, end)` **Description**: Returns `true` if any bit within the range from `start` (inclusive) to `end` (exclusive) is set (`true`), otherwise returns `false`. ``` -------------------------------- ### Set Difference Operations Source: https://context7.com/lemire/typedfastbitset.js/llms.txt These methods calculate the difference between bitsets. `difference_size` returns the count of elements in the first set but not the second. `new_difference` creates a new bitset with these elements. `difference` modifies the first bitset in-place. `difference2` computes A - B and stores the result in the second bitset. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3, 4, 5]); const b = new TypedFastBitSet([3, 4, 5, 6, 7]); // Get difference size without modifying const diffSize = a.difference_size(b); console.log(diffSize); // Output: 2 (elements 1 and 2) // Create new bitset with difference (a - b) const diffResult = a.new_difference(b); console.log(diffResult.array()); // Output: [1, 2] // In-place difference: removes from 'c' elements that are in 'd' const c = new TypedFastBitSet([1, 2, 3, 4, 5]); const d = new TypedFastBitSet([2, 4]); c.difference(d); console.log(c.array()); // Output: [1, 3, 5] // difference2: computes A - B and stores result in B const e = new TypedFastBitSet([1, 2, 3, 4, 5]); const f = new TypedFastBitSet([3, 4]); e.difference2(f); // f now contains elements in e but not originally in f console.log(f.array()); // Output: [1, 2, 5] ``` -------------------------------- ### Range Operations in TypedFastBitSet Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Efficiently add, remove, and check for values within a specified range using `addRange`, `removeRange`, and `hasAnyInRange`. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const bitset = new TypedFastBitSet(); // Add range from 10 (inclusive) to 20 (exclusive) bitset.addRange(10, 20); console.log(bitset.array()); // Output: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] console.log(bitset.size()); // Output: 10 // Remove range from 13 to 17 bitset.removeRange(13, 17); console.log(bitset.array()); // Output: [10, 11, 12, 17, 18, 19] // Check if any value exists in a range console.log(bitset.hasAnyInRange(15, 18)); // Output: true (17 is in range) console.log(bitset.hasAnyInRange(13, 17)); // Output: false (no values in this range) ``` -------------------------------- ### Symmetric Difference (XOR/Change) Operations Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Compute the symmetric difference (elements in either set, but not both). `change_size` returns the count, `new_change` creates a new bitset, and `change` performs the operation in-place. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3, 4]); const b = new TypedFastBitSet([3, 4, 5, 6]); // Get symmetric difference size const changeSize = a.change_size(b); console.log(changeSize); // Output: 4 (elements 1, 2, 5, 6) // Create new bitset with symmetric difference const changeResult = a.new_change(b); console.log(changeResult.array()); // Output: [1, 2, 5, 6] // In-place symmetric difference const c = new TypedFastBitSet([1, 2, 3]); const d = new TypedFastBitSet([2, 3, 4]); c.change(d); console.log(c.array()); // Output: [1, 4] ``` -------------------------------- ### Set Operations Source: https://github.com/lemire/typedfastbitset.js/blob/master/README.md Operations that return a new bitmap representing the result of a set operation between the current bitmap and another. ```APIDOC ## new_union(other) ### Description Returns a new bitmap representing the union of the current bitmap and the `other` bitmap (`this | other`). ### Method `new_union` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to perform the union with. ### Request Example ```json { "example": "bitmap1.new_union(bitmap2)" } ``` ### Response #### Success Response (200) - **TypedFastBitSet** - A new bitmap representing the union. #### Response Example ```json { "example": "newBitmap" } ``` ## new_intersection(other) ### Description Returns a new bitmap representing the intersection of the current bitmap and the `other` bitmap (`this & other`). ### Method `new_intersection` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to perform the intersection with. ### Request Example ```json { "example": "bitmap1.new_intersection(bitmap2)" } ``` ### Response #### Success Response (200) - **TypedFastBitSet** - A new bitmap representing the intersection. #### Response Example ```json { "example": "newBitmap" } ``` ## new_difference(other) ### Description Returns a new bitmap representing the difference between the current bitmap and the `other` bitmap (`this & ~other`). ### Method `new_difference` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to subtract from the current one. ### Request Example ```json { "example": "bitmap1.new_difference(bitmap2)" } ``` ### Response #### Success Response (200) - **TypedFastBitSet** - A new bitmap representing the difference. #### Response Example ```json { "example": "newBitmap" } ``` ## new_change(other) ### Description Returns a new bitmap representing the symmetric difference (change) between the current bitmap and the `other` bitmap (`this ^ other`). ### Method `new_change` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **other** (TypedFastBitSet) - Required - The other bitmap to compute the symmetric difference with. ### Request Example ```json { "example": "bitmap1.new_change(bitmap2)" } ``` ### Response #### Success Response (200) - **TypedFastBitSet** - A new bitmap representing the symmetric difference. #### Response Example ```json { "example": "newBitmap" } ``` ``` -------------------------------- ### Set Intersection Operations Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Use these methods to find common elements between bitsets. `intersects` checks for overlap, `intersection_size` returns the count, `new_intersection` creates a new bitset with common elements, and `intersection` modifies the bitset in-place. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3, 4, 5]); const b = new TypedFastBitSet([3, 4, 5, 6, 7]); // Check if bitsets intersect (have common values) console.log(a.intersects(b)); // Output: true // Get intersection size without creating new bitset const intersectionSize = a.intersection_size(b); console.log(intersectionSize); // Output: 3 // Create new bitset containing intersection const intersectionResult = a.new_intersection(b); console.log(intersectionResult.array()); // Output: [3, 4, 5] // In-place intersection (modifies 'a') const c = new TypedFastBitSet([1, 2, 3, 4, 5]); const d = new TypedFastBitSet([2, 4, 6]); c.intersection(d); console.log(c.array()); // Output: [2, 4] ``` -------------------------------- ### TypedFastBitSet Union Operations Source: https://context7.com/lemire/typedfastbitset.js/llms.txt Perform union operations on two TypedFastBitSets. `union_size` returns the size of the union without creating a new object, `new_union` creates a new bitset with the union, and `union` performs an in-place union. ```javascript const { TypedFastBitSet } = require("typedfastbitset"); const a = new TypedFastBitSet([1, 2, 3, 4, 5]); const b = new TypedFastBitSet([4, 5, 6, 7, 8]); // Get union size without modifying either bitset const unionSize = a.union_size(b); console.log(unionSize); // Output: 8 // Create new bitset containing union const unionResult = a.new_union(b); console.log(unionResult.array()); // Output: [1, 2, 3, 4, 5, 6, 7, 8] // In-place union (modifies 'a') const c = new TypedFastBitSet([1, 2, 3]); const d = new TypedFastBitSet([3, 4, 5]); c.union(d); console.log(c.array()); // Output: [1, 2, 3, 4, 5] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.