diff --git a/types/fastbitset/fastbitset-tests.ts b/types/fastbitset/fastbitset-tests.ts new file mode 100644 index 0000000000..a08c6da34d --- /dev/null +++ b/types/fastbitset/fastbitset-tests.ts @@ -0,0 +1,27 @@ +import FastBitSet = require('fastbitset'); + +const bitSet = new FastBitSet(); + +bitSet.add(1); +bitSet.has(1); +bitSet.add(2); + +bitSet.add(10); +bitSet.array(); + +let otherBitSet = new FastBitSet([1, 2, 3, 10]); + +otherBitSet.difference(bitSet); +otherBitSet.union_size(bitSet); +otherBitSet.union(bitSet); +otherBitSet.new_union(bitSet); +otherBitSet.new_intersection(bitSet); +otherBitSet.intersection_size(bitSet); +otherBitSet.difference_size(bitSet); +otherBitSet.intersects(bitSet); +otherBitSet.intersection(bitSet); + +otherBitSet = bitSet.clone(); +otherBitSet.equals(bitSet); +otherBitSet.forEach(value => value); +otherBitSet.trim(); diff --git a/types/fastbitset/index.d.ts b/types/fastbitset/index.d.ts new file mode 100644 index 0000000000..c2772cf8f4 --- /dev/null +++ b/types/fastbitset/index.d.ts @@ -0,0 +1,114 @@ +// Type definitions for fastbitset 0.2 +// Project: https://github.com/lemire/FastBitSet.js +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class FastBitSet { + constructor(iterable?: Iterable); + + /** Add the value (Set the bit at `index` to `true`) */ + add(index: number): void; + + /** Return an array with the set bit locations (values) */ + array(): number[]; + + /** + * Tries to add the value (Set the bit at `index` to `true`), returns `1` if the + * value was added, returns `0` if the value was already present + */ + checkedAdd(index: number): 1 | 0; + + /** Remove all values, reset memory usage */ + clear(): void; + + /** Creates a copy of this bitmap */ + clone(): FastBitSet; + + /** + * Computes the difference between this bitset and another one, + * the current bitset is modified (and returned by the function) + */ + difference(otherbitmap: FastBitSet): FastBitSet; + + /** Computes the size of the difference between this bitset and another one */ + difference_size(otherbitmap: FastBitSet): number; + + /** + * Computes the intersection between this bitset and another one, + * the current bitmap is modified + */ + equals(otherbitmap: FastBitSet): boolean; + + /** If the value was not in the set, add it, otherwise remove it (flip bit at `index`) */ + flip(index: number): void; + + /** Return an array with the set bit locations (values) */ + forEach(fnc: (index: number) => void): void; + + /** fast function to compute the Hamming weight of a 32-bit unsigned integer */ + hammingWeight(v: number): number; + + /** fast function to compute the Hamming weight of four 32-bit unsigned integers */ + hammingWeight4(v1: number, v2: number, v3: number, v4: number): number; + + /** Is the value contained in the set? Is the bit at `index` `true` or `false`? */ + has(index: number): boolean; + + /** + * Check if this bitset intersects with another one, + * no bitmap is modified + */ + intersects(otherbitmap: FastBitSet): boolean; + + /** + * Computes the intersection between this bitset and another one, + * the current bitmap is modified (and returned by the function) + */ + intersection(otherbitmap: FastBitSet): FastBitSet; + + /** Computes the size of the intersection between this bitset and another one */ + intersection_size(otherbitmap: FastBitSet): number; + + /** Return `true` if no bit is set */ + isEmpty(index: number): boolean; + + /** + * Computes the intersection between this bitset and another one, + * a new bitmap is generated + */ + new_intersection(otherbitmap: FastBitSet): FastBitSet; + + /** + * Computes the difference between this bitset and another one, + * a new bitmap is generated + */ + new_difference(otherbitmap: FastBitSet): FastBitSet; + + new_union(otherbitmap: FastBitSet): FastBitSet; + + /** Set the bit at `index` to `false` */ + remove(index: number): void; + + /** Resize the bitset so that we can write a value at `index` */ + resize(index: number): void; + + /** How many values stored in the set? How many set bits? */ + size(): number; + + /** Returns a string representation */ + toString(): string; + + /** Reduce the memory usage to a minimum */ + trim(): void; + + /** + * Computes the union between this bitset and another one, + * the current bitset is modified (and returned by the function) + */ + union(otherbitmap: FastBitSet): FastBitSet; + + /** Computes the size union between this bitset and another one */ + union_size(otherbitmap: FastBitSet): number; +} + +export = FastBitSet; diff --git a/types/fastbitset/tsconfig.json b/types/fastbitset/tsconfig.json new file mode 100644 index 0000000000..65f9eaee5c --- /dev/null +++ b/types/fastbitset/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fastbitset-tests.ts" + ] +} diff --git a/types/fastbitset/tslint.json b/types/fastbitset/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fastbitset/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }