roaring-wasm-papandreou
Version:
WebAssembly port of Roaring Bitmaps for NodeJS
420 lines (419 loc) • 16.2 kB
TypeScript
/// <reference types="node" />
import RoaringUint32Array = require('./RoaringUint32Array')
import RoaringUint8Array = require('./RoaringUint8Array')
/**
* A Roaring Bitmap that supports 32 bit unsigned integers.
*
* The roaring bitmap allocates in WASM memory, remember to dispose
* the RoaringBitmap32 when not needed anymore to release WASM memory.
*
*
* @class RoaringBitmap32
*/
declare class RoaringBitmap32 {
private _ptr
private _frozenBuf
/**
* Creates a new roaring bitmap adding the specified values.
*
* The roaring bitmap allocates in WASM memory, remember to dispose
* the RoaringBitmap32 when not needed anymore to release WASM memory.
* @constructor
* @param {(RoaringUint32Array | Iterable<number>)} values The values to add
* @memberof RoaringBitmap32
*/
constructor(values?: RoaringUint32Array | Iterable<number>)
/**
* Creates a new roaring bitmap deserializing it from a buffer
*
* The roaring bitmap allocates in WASM memory, remember to dispose
* the RoaringBitmap32 when not needed anymore to release WASM memory.
*
* @static
* @param {(RoaringUint8Array | Uint8Array | Iterable<number>)} buffer The buffer to deserialize
* @param {boolean} [portable=false] If true, deserialization is compatible with the Java and Go versions of the library.
* If false, deserialization is compatible with the C version of the library. Default is false.
* @returns {RoaringBitmap32} The reulting bitmap. Remember to dispose the instance when finished using it.
* @memberof RoaringBitmap32
*/
static deserialize(buffer: RoaringUint8Array | Uint8Array | Iterable<number>, portable?: boolean, frozen?: boolean): RoaringBitmap32
/**
* Utility function that serializes an array of uint32 to a new NodeJS buffer.
* The returned buffer is automatically garbage collected.
*
* @static
* @param {(RoaringUint32Array | Iterable<number>)} values
* @param {boolean} [portable=false] If true, serialization is compatible with the Java and Go versions of the library.
* If false, serialization is compatible with the C version of the library. Default is false.
* @returns {Buffer} The NodeJS buffer containing the serialized data.
* @memberof RoaringBitmap32
*/
static serializeArrayToNewBuffer(values: RoaringUint32Array | Iterable<number>, portable?: boolean): Buffer
/**
* Utility function that deserializes a RoaringBitmap32 serialized in a buffer to an Array<number> of values.
* The array can be very big, be careful when you use this function.
*
* @static
* @param {(RoaringUint8Array | Uint8Array | Iterable<number>)} buffer The buffer to deserialize.
* @param {boolean} [portable=false] If true, deserialization is compatible with the Java and Go versions of the library.
* If false, deserialization is compatible with the C version of the library. Default is false.
* @returns {number[]} All the values in the bitmap.
* @memberof RoaringBitmap32
*/
static deserializeToArray(buffer: RoaringUint8Array | Uint8Array | Iterable<number>, portable?: boolean): number[]
/**
* Utility function that deserializes a RoaringBitmap32 serialized in a buffer to a Set<number> of values.
* The array can be very big, be careful when you use this function.
*
* @static
* @param {(RoaringUint8Array | Uint8Array | Iterable<number>)} buffer The buffer to deserialize.
* @param {boolean} [portable=false] If true, deserialization is compatible with the Java and Go versions of the library.
* If false, deserialization is compatible with the C version of the library. Default is false.
* @returns {number[]} All the values in the bitmap.
* @memberof RoaringBitmap32
*/
static deserializeToSet(buffer: RoaringUint8Array | Uint8Array | Iterable<number>, portable?: boolean): Set<number>
/**
* Returns true if this instance was disposed.
*
* @readonly
* @property
* @type {boolean}
* @memberof RoaringBitmap32
*/
readonly isDisposed: boolean
/**
* Disposes this object freeing all WASM memory associated to it.
* Is safe to call this method more than once.
*
* @returns {boolean} True if disposed during this call, false if not.
* @memberof RoaringBitmap32
*/
dispose(): boolean
/**
* Throws an exception if this object was disposed before.
*
* @returns {(void | never)}
* @memberof RoaringBitmap32
*/
throwIfDisposed(): void | never
/**
* Get the cardinality of the bitmap (number of elements).
*
* @returns {number} Number of elements in this bitmap.
* @memberof RoaringBitmap32
*/
cardinality(): number
/**
* Returns true if the bitmap has no elements.
*
* @returns {boolean} True if the bitmap is empty.
* @memberof RoaringBitmap32
*/
isEmpty(): boolean
/**
* Adds a 32 bit unsigned integer value.
* Values are unique, this function does nothing if the value already exists.
*
* @param {number} value 32 bit unsigned integer to add in the set.
* @memberof RoaringBitmap32
*/
add(value: number): void
/**
* Adds a 32 bit unsigned integer value checking if the bitmap changes.
* Use add() if you don't need to know if something changed.
* Values are unique, this function does nothing and returns false if the value already exists.
*
* @param {number} value 32 bit unsigned integer to add in the set.
* @returns {boolean} True if the bitmap changed, false if not.
* @memberof RoaringBitmap32
*/
addChecked(value: number): boolean
/**
* Adds multiple values.
* Using this is faster than calling add() multiple times.
* Inserting ordered or partially ordered arrays is faster.
*
* @param {(RoaringUint32Array | Iterable<number>)} values The values to add.
* @memberof RoaringBitmap32
*/
addMany(values: RoaringUint32Array | Iterable<number>): void
/**
* Removes a value from the set.
* If the value does not exists, this function does nothing.
*
* @param {number} value The value to remove.
* @memberof RoaringBitmap32
*/
remove(value: number): void
/**
* Removes a value from the set checking if the bitmap changes.
* Use remove() if you don't need to know if something changed.
* If the value does not exists, this function does nothing and returns false.
*
* @param {number} value 32 bit unsigned integer to remove from the set.
* @returns {boolean} True if the bitmap changed, false if not.
* @memberof RoaringBitmap32
*/
removeChecked(value: number): boolean
/**
* Gets the maximum value stored in the bitmap.
* If the bitmap is empty, returns 0.
*
* @returns {number} The maximum 32 bit unsigned integer or 0 if empty.
* @memberof RoaringBitmap32
*/
maximum(): number
/**
* Gets the minimum value stored in the bitmap.
* If the bitmap is empty, returns 0xFFFFFFFF
*
* @returns {number} The minimum 32 bit unsigned integer or 0xFFFFFFFF if empty.
* @memberof RoaringBitmap32
*/
minimum(): number
/**
* Checks whether the given value is contained in the set.
*
* @param {number} value The value to look for.
* @returns {boolean} True if value exists in the set, false if not.
* @memberof RoaringBitmap32
*/
contains(value: number): boolean
/**
* Returns true if the bitmap is subset of the other.
*
* @param {RoaringBitmap32} other the other bitmap
* @returns {boolean}
* @memberof RoaringBitmap32
*/
isSubset(other: RoaringBitmap32): boolean
/**
* Returns true if this bitmap is strict subset of the other.
*
* @param {RoaringBitmap32} other The other bitmap
* @returns {boolean} True if this bitmap is a strict subset of other
* @memberof RoaringBitmap32
*/
isStrictSubset(other: RoaringBitmap32): boolean
/**
* Converts the bitmap to an array.
* The array may be very big, use this function with caution.
* The returned RoaringUint32Array is allocated in WASM memory and not garbage collected,
* it need to be freed manually calling dispose().
*
* @returns {RoaringUint32Array} The RoaringUint32Array. Remember to manually dispose to free the memory.
* @memberof RoaringBitmap32
*/
toRoaringUint32Array(): RoaringUint32Array
/**
* Converts the bitmap to a JS array.
* The resulting array may be very big, use this function with caution.
*
* @returns {number[]} The array containing all values in the bitmap.
* @memberof RoaringBitmap32
*/
toArray(): number[]
/**
* Converts the bitmap to a JS Set<number>.
* The resulting set may be very big, use this function with caution.
*
* @returns {Set<number>} The set containing all values in the bitmap.
* @memberof RoaringBitmap32
*/
toSet(): Set<number>
/**
* Converts the bitmap to a JS Uint32Array.
* The resulting array may be very big, use this function with caution.
*
* @returns {Uint32Array} The array containing all values in the bitmap.
* @memberof RoaringBitmap32
*/
toUint32Array(): Uint32Array
/**
* Checks wether two roaring bitmap contains the same data.
*
* @param {RoaringBitmap32} other
* @returns {boolean} True if the bitmaps contains the same data, false if not.
* @memberof RoaringBitmap32
*/
equals(other: RoaringBitmap32): boolean
/**
* Negates in place the bitmap within a specified interval.
* Areas outside the range are passed through unchanged.
*
* @param {number} start Range start.
* @param {number} end Range end.
* @memberof RoaringBitmap32
*/
flipRange(start: number, end: number): void
/**
* Optimizes the bitmap releasing unused memory and compressing containers.
* Returns true if something changed.
*
* @returns {boolean} True if something changed.
* @memberof RoaringBitmap32
*/
optimize(): boolean
/**
* If the size of the roaring bitmap is strictly greater than rank, then
* this function returns the element of given rank.
* Otherwise, it returns NaN.
*
* @param {number} rank Element rank
* @returns {number} element or NaN
* @memberof RoaringBitmap32
*/
select(rank: number): number
/**
* Computes the size of the intersection between two bitmaps.
* Both bitmaps are unchanged.
*
* @param {RoaringBitmap32} other
* @returns {number} Cardinality of the intersection between two bitmaps.
* @memberof RoaringBitmap32
*/
andCardinality(other: RoaringBitmap32): number
/**
* Computes the size of the union of two bitmaps.
* Both bitmaps are unchanged.
*
* @param {RoaringBitmap32} other
* @returns {number} Cardinality of the union of two bitmaps.
* @memberof RoaringBitmap32
*/
orCardinality(other: RoaringBitmap32): number
/**
* Computes the size of the difference (andnot) of two bitmaps.
* Both bitmaps are unchanged.
*
* @param {RoaringBitmap32} other
* @returns {number} Cardinality of the difference (andnot) of two bitmaps.
* @memberof RoaringBitmap32
*/
andNotCardinality(other: RoaringBitmap32): number
/**
* Computes the size of the symmetric difference (xor) between two bitmaps.
* Both bitmaps are unchanged.
*
* @param {RoaringBitmap32} other
* @returns {number} Cardinality of the symmetric difference (xor) of two bitmaps.
*/
xorCardinality(other: RoaringBitmap32): number
/**
* Intersects this bitmap with another.
* Removes the elements from this bitmap that don't exists in the other.
* Stores the result in this bitmap.
* The provided bitmap is not modified.
*
* @param {RoaringBitmap32} other
* @memberof RoaringBitmap32
*/
andInPlace(other: RoaringBitmap32): void
/**
* Adds the element of the other bitmap into this bitmap.
* Stores the result in this bitmap.
* The provided bitmap is not modified.
*
* @param {RoaringBitmap32} other
* @memberof RoaringBitmap32
*/
orInPlace(other: RoaringBitmap32): void
/**
* Computes the difference between two bitmaps.
* Stores the result in this bitmap.
* The provided bitmap is not modified.
*
* @param {RoaringBitmap32} other
* @memberof RoaringBitmap32
*/
xorInPlace(other: RoaringBitmap32): void
/**
* Compute the difference between this and the provided bitmap,
* writing the result in the current bitmap.
* The provided bitmap is not modified.
*
* @param {RoaringBitmap32} other
* @memberof RoaringBitmap32
*/
andNotInPlace(other: RoaringBitmap32): void
/**
* Returns the number of integers that are smaller or equal to the given value.
*
* @param {number} value The value to rank
* @returns {number} The number of values smaller than the given value
* @memberof RoaringBitmap32
*/
rank(value: number): number
/**
* Check whether the two bitmaps intersect (have at least one element in common).
*
* @param {RoaringBitmap32} other The other bitmap.
* @returns {boolean} True if the two bitmaps intersects, false if not.
* @memberof RoaringBitmap32
*/
intersects(other: RoaringBitmap32): boolean
/**
* Computes the Jaccard index between two bitmaps.
* (Also known as the Tanimoto distance, or the Jaccard similarity coefficient)
* See https://en.wikipedia.org/wiki/Jaccard_index
*
* The Jaccard index is undefined if both bitmaps are empty.
*
* @returns {number} The Jaccard index
* @memberof RoaringBitmap32
*/
jaccardIndex(other: RoaringBitmap32): number
/**
* How many bytes are required to serialize this bitmap.
*
* @param {boolean} [portable=false] If true, deserialization is compatible with the Java and Go versions of the library.
* If false, deserialization is compatible with the C version of the library. Default is false.
* @memberof RoaringBitmap32
*/
getSerializationSizeInBytes(portable?: boolean): number
/**
* Serializes a bitmap to a byte buffer allocated in WASM memory.
*
* The returned RoaringUint8Array is allocated in WASM memory and not garbage collected,
* it need to be freed manually calling dispose().
*
* @param {boolean} [portable=false] If true, serialization is compatible with the Java and Go versions of the library.
* If false, serialization is compatible with the C version of the library. Default is false.
* @returns {RoaringUint8Array} The RoaringUint8Array. Remember to manually dispose to free the memory.
* @memberof RoaringBitmap32
*/
serializeToRoaringUint8Array(portable?: boolean): RoaringUint8Array
/**
* Serializes a bitmap to a typed Uint8Array.
* The returned array is automatically garbage collected and there is no need to be disposed manually.
*
* @param {boolean} [portable=false] If true, serialization is compatible with the Java and Go versions of the library.
* If false, serialization is compatible with the C version of the library. Default is false.
* @returns {Uint8Array} The Uint8Array that contains the serialized bitmap
* @memberof RoaringBitmap32
*/
serializeToUint8Array(portable?: boolean): Uint8Array
/**
* Serializes a bitmap to a NodeJS buffer.
* The returned buffer is automatically garbage collected and there is no need to be disposed manually.
*
* @param {boolean} [portable=false] If true, serialization is compatible with the Java and Go versions of the library.
* If false, serialization is compatible with the C version of the library. Default is false.
* @returns {Buffer} The NodeJS Buffer that contains the serialized bitmap
* @memberof RoaringBitmap32
*/
serializeToNodeBuffer(portable?: boolean): Buffer
/**
* Reads a bitmap from a serialized version.
* Throws an error if deserialization failed.
*
* @param {(RoaringUint8Array | Uint8Array | Iterable<number>)} buffer
* @param {boolean} [portable=false] If true, deserialization is compatible with the Java and Go versions of the library.
* If false, deserialization is compatible with the C version of the library. Default is false.
* @returns {void}
* @memberof RoaringBitmap32
*/
deserialize(buffer: RoaringUint8Array | Uint8Array | Iterable<number>, portable?: boolean, frozen?: boolean): void
}
export = RoaringBitmap32