/** * Utility class to inflate zlib compressed ArrayBuffers into a custom ArrayBuffer, could be a SharedArrayBuffer. * @param outputBuffer - Buffer where the uncompressed data will be written. * @param [size] - The expected final size of the uncompressed data. Defaults to the full size of `outputBuffer` */ export class DSBINInflate { constructor(outputBuffer: Uint8Array, size?: number); /** * Inflates the `inputBuffer` data into the `outputBuffer` optionally a final `size` can be specified. * @param inputBuffer - The compressed data. * @param outputBuffer - Buffer where the uncompressed data will be written. * @param [size] - The expected final size of the uncompressed data. Defaults to the full size of `outputBuffer` */ static inflate(inputBuffer: Uint8Array, outputBuffer: Uint8Array, size?: number): number; /** * Method called when decompression is completed. * @param status - The status of the system. */ onEnd(status: number): void; } /** * Multi-threaded DSBIN file loader. */ export class DSBINLoader { /** * Loads a DSBIN from a local file. * @param file - The local file to load. * @param heap - The heap where the file will be loaded. */ static loadFromFile(file: File, heap: Heap): Promise; /** * Loads a DSBIN from a URL. * @param url - The URL from which the DSBIN should be loaded. * @param heap - The heap where the file will be loaded. */ static loadFromURL(url: string, heap: Heap): Promise; } export type IntTypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray; /** * Simple wrapper to provide atomics-like functionality in systems that lack the functionality. */ export const Atomize: Atomics | AtomicsLike; /** * Simple stubbing for Atomics. * WARNING: Does not implement any kind of synchronization. */ export class AtomicsLike { /** * Adds a given value at a given position in the array and returns the old value at that position * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. */ add(typedArray: IntTypedArray, index: number, value: number): number; /** * Computes a bitwise AND with a given value at a given position in the array, and returns the old value at * that position. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. */ and(typedArray: IntTypedArray, index: number, value: number): number; /** * Exchanges a given replacement value at a given position in the array, if a given expected value equals the * old value. It returns the old value at that position whether it was equal to the expected value or not * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param expectedValue - The value to check for equality. * @param replacementValue - The number to exchange. */ compareExchange(typedArray: IntTypedArray, index: number, expectedValue: number, replacementValue: number): number; /** * Stores a given value at a given position in the array and returns the old value at that position. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. */ exchange(typedArray: IntTypedArray, index: number, value: number): number; /** * The static Atomics.isLockFree() method is used to determine whether to use locks or atomic operations. * It returns true, if the given size is one of the BYTES_PER_ELEMENT property of integer TypedArray types. * @param size - The size in bytes to check. */ isLockFree(size: number): boolean; /** * Returns a value at a given position in the array. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. */ load(typedArray: IntTypedArray, index: number): number; /** * Notifies up some agents that are sleeping in the wait queue. * WARNING: NOT SUPPORTED IN SYSTEMS WITHOUT Atomics. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param count - The number of threads to be notified. */ notify(typedArray: Int32Array, index: number, count: number): number; /** * Computes a bitwise OR with a given value at a given position in the array, and returns the old value at that * position. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. */ or(typedArray: IntTypedArray, index: number, value: number): number; /** * Stores a given value at the given position in the array and returns that value. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. */ store(typedArray: IntTypedArray, index: number, value: number): number; /** * Substracts a given value at a given position in the array and returns the old value at that position. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. */ sub(typedArray: IntTypedArray, index: number, value: number): number; /** * Verifies that a given position in an Int32Array still contains a given value and if so sleeps, awaiting a * wakeup or a timeout. It returns a string which is either "ok", "not-equal", or "timed-out". * WARNING: NOT SUPPORTED IN SYSTEMS WITHOUT Atomics. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. * @param timeout - Time, in milliseconds, to wait before the operation times out. */ wait(typedArray: Int32Array, index: number, value: number, timeout: number): string; /** * Computes a bitwise XOR with a given value at a given position in the array, and returns the old value at * that position. * @param typedArray - The typed array instance where the operation will be performed. * @param index - The index at which the operation will be performed. * @param value - The value to use while performing the operation. */ xor(typedArray: IntTypedArray, index: number, value: number): number; } /** * Lightweight Heap class used to very naively allocate memory within an ArrayBuffer. Thread safe. * Uses a stack approach to memory allocation/deallocation, only when the last memory block in the stack is freed * the allocatable memory increases. * @param buffer - The buffer to use or the size in bytes to allocate. */ export class Heap { constructor(buffer: ArrayBuffer | SharedArrayBuffer | number); /** * Convenience property that returns the size in bytes of 1KB. */ static sizeOf1KB: number; /** * Convenience property that returns the size in bytes of 1MB. */ static sizeOf1MB: number; /** * Convenience property that returns the size in bytes of 1GB. */ static sizeOf1GB: number; /** * Convenience property that returns the max size of the heap. */ static maxHeapSize: number; /** * Convenience property that return the max usable size of a heap allocated with the max heap size. */ static maxAllocSize: number; /** * The memory buffer managed by this heap. */ buffer: ArrayBuffer | SharedArrayBuffer; /** * Is the buffer in this heap an instance of SharedArrayBuffer */ shared: boolean; /** * DataView of the memory buffer. */ dataView: DataView; /** * The size, in bytes, of this heap. */ size: number; /** * Total memory used. * Freeing a memory block does not guarantee that this number will increase. */ usedMemory: number; /** * Total usable memory in the heap. */ freeMemory: number; /** * The memory address that will be assigned to the next allocation. */ allocOffset: number; /** * Allocates a new memory block. * The allocated memory is rounded up to the nearest multiple of 4 and padded by 4 bytes at the end of the block. * @param size - The amount of memory, in bytes, to allocate. */ malloc(size: number): MemoryBlock; /** * Allocates a new memory block and guarantees that the memory block will be empty. * @param size - The amount of memory, in bytes, to allocate. */ calloc(size: number): MemoryBlock; /** * Frees the specified memory block. Memory is not reusable until the memory stack can be reduced by freeing the * last allocated memory block. * @param memory - The memory block to free. */ free(memory: MemoryBlock): void; /** * Shrinks the specified memory block to the specified size. * @param memory - The memory block to shrink. * @param size - The new memory size for the block, must be smaller than the its current size. */ shrink(memory: MemoryBlock, size: number): void; } /** * Class to encapsulate an ArrayBuffer with utility views to read/write data. * Instantiates a memory block in the specified heap, at the memory address and the specified size. * Memory blocks can easily be recreated in web workers. * @param heap - The heap which will contain the memory. * @param address - The byte address of the beginning of the memory. * @param size - The size, in bytes, of this memory block. */ export class MemoryBlock { constructor(heap: Heap, address: number, size: number); /** * The byte address of this memory block in its heap. */ address: number; /** * The heap this memory block belongs to. */ heap: Heap; /** * The ArrayBuffer this memory is tied to. */ buffer: ArrayBuffer | SharedArrayBuffer; /** * The size, in bytes, of this memory block. */ size: number; /** * A DataView instance bound to the memory accessible by this memory block. */ dataView: DataView; /** * Frees this memory block, this function just calls `free` on the heap. */ free(): void; } /** * This class represents a position in a memory block. * @param memory - The memory to which this Pointer will be bound to. * @param [address] - The address of this pointer relative to the memory it is bound to. * @param [type] - The type of this pointer, defaults to Uint8. */ export class Pointer { constructor(memory: Heap | MemoryBlock, address?: number, type?: Type); /** * Returns a copy of the specified pointer. * @param other - The pointer to copy. */ static copy(other: Pointer): Pointer; /** * Returns the memory this pointer is bound to. */ memory: Heap | MemoryBlock; /** * DataView of the memory this pointer is bound to. */ view: DataView; /** * The address of this pointer relative to the memory it is bound to. */ address: number; /** * The type of this pointer. */ type: Type; /** * Given its type, returns the numeric value at this pointer's address. */ value: number; /** * Casts the value at this pointer's address to the specified type. * @param type - The desired type for the result. */ castValue(type: Type): number; /** * Moves this pointer's address by the specified offset, takes into account the pointer's type. * i.e. an offset of 1 will move a Uint32 pointer 4 bytes while a Uint8 pointer will only move 1 byte. * @param offset - How many places should the pointer move. */ move(offset: number): void; /** * Returns a value from memory at the pointer's address plus the given offset. * @param offset - The offset, in the pointer's type size, where the value should be read from. */ getValueAt(offset: number): number; /** * Stores a value in memory at the pointer's address plus the given offset. * @param offset - The offset, in the pointer's type size, where the value will be set. * @param value - The number value to set. */ setValueAt(offset: number, value: number): any; /** * Casts the value at the desired offset (with respect to the pointer) to the desired type. * @param offset - The offset with respect to the pointer, in bytes, of the value to cast. * @param type - The desired type of the result. */ castValueAt(offset: number, type: Type): number; /** * Utility function to read an Int8 at the specified offset. * @param offset - The offset with respect to the pointer, in bytes, of the value to read. */ getInt8(offset: number): number; /** * Utility function to read an Int16 at the specified offset. * @param offset - The offset with respect to the pointer, in bytes, of the value to read. */ getInt16(offset: number): number; /** * Utility function to read an Int32 at the specified offset. * @param offset - The offset with respect to the pointer, in bytes, of the value to read. */ getInt32(offset: number): number; /** * Utility function to read a Uint8 at the specified offset. * @param offset - The offset with respect to the pointer, in bytes, of the value to read. */ getUint8(offset: number): number; /** * Utility function to read a Uint16 at the specified offset. * @param offset - The offset with respect to the pointer, in bytes, of the value to read. */ getUint16(offset: number): number; /** * Utility function to read a Uint32 at the specified offset. * @param offset - The offset with respect to the pointer, in bytes, of the value to read. */ getUint32(offset: number): number; /** * Utility function to read a Float32 at the specified offset. * @param offset - The offset with respect to the pointer, in bytes, of the value to read. */ getFloat32(offset: number): number; } /** * Creates a new type instance. * In DEBUG mode performs checks if the bit and byte sizes are consistent. * @param name - The name of the type to create * @param byteSize - Size in bytes of this type * @param bitSize - Size in bits of this type, must be x8 bigger than `byteSize` */ export class Type { constructor(name: string, byteSize: number, bitSize: number); /** * Inspects the specified type and returns it's size. This method is equivalent to the `byteSize` property of the * type instance. When in DEBUG mode this method checks if the parameter `t` is an instance of Type. * @param t - The type to inspect */ static sizeOf(t: Type): number; /** * Inspects the specified type and returns whether or not this type is valid. * @param t - The type to inspect. */ static isType(t: Type): boolean; /** * Inspects the specified type and returns whether or not the type is a primitive type. * In DEBUG mode, performs a check to validate the type. * @param t - The type to inspect */ static isPrimitive(t: Type): boolean; /** * If a type with the specified name exists, this function returns it. * @param name - The name of the type to look for. */ static getTypeByName(name: string): Type | null; /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } /** * Utility function, the same as `Type.isType` * @param t - The type to inspect */ export function isType(t: Type): boolean; /** * Utility function, the same as `Type.isPrimitive` * @param t - The type to inspect */ export function isPrimitiveType(t: Type): boolean; /** * Utility function, the same as `Type.sizeOf` * @param t - The type to inspect */ export function sizeof(t: Type): number; /** * Utility function, the same as `Type.getTypeByName` * @param name - The name of the type to look for. */ export function typeByName(name: string): Type; export class _Int8 extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Int8: _Int8; export class _Int16 extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Int16: _Int16; export class _Int32 extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Int32: _Int32; export class _Uint8 extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Uint8: _Uint8; export class _Uint16 extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Uint16: _Uint16; export class _Uint32 extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Uint32: _Uint32; export class _Float32 extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Float32: _Float32; export class _Void extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const Void: _Void; /** * Class to create and run filters on tables. * Creates a Filter instance bound to the specified table. * @param table - The table this filter will be bound to. * @param [workerCount] - The number of workers to spawn, should be the same as physical cores in the system, defaults to automatically detected. * @param [heap] - The heap to use to allocate the filter results memory, defaults to using the same heap where the table is allocated. */ export class Filter { constructor(table: Table, workerCount?: number, heap?: Heap); /** * Returns an object that can be added to the `resultDescription` array to include the index of the resulting rows */ static rowIndexResult: any; /** * The size, in bytes, of a results row. */ resultRowSize: number; /** * An array of objects describing the desired fields in the filter's result. * WARNING: Do not modify this array, assign a brand new array instead. */ resultDescription: object[]; /** * Utility function to create an object describing a result field for the column with the specified name. * If the `columnName` parameter is omitted or is set to `null`, an object that adds the index of the resulting row * will be returned. * @param columnName - The name of the column for which to create a result field object. Defaults to `null`. * @param [asName] - The name of the column in the resulting table */ resultFieldForColumn(columnName: string | null, asName?: string): any; /** * Utility function to create an object describing a result field for the column with the specified index. * If the `columnIndex` parameter is omitted or is set to `null`, an object that adds the index of the resulting row * will be returned. * @param columnIndex - The index of the column for which to create a result field object. Defaults to `null`. */ resultFieldForColumnIndex(columnIndex: number | null): any; /** * Runs this filter with the specified set of rules. * @param rules - The rules to run this filter with. * @param [mode] - The mode in which the specified rules should be interpreted. * @param [table = null] - A table where the results should be written */ run(rules: FilterExpression, mode?: FilterExpressionMode, table?: Table): Promise; } /** * Enum that represents the different modes in which a filter can be interpreted. * * Can be "conjunctive normal form" boolean logic: * https://en.wikipedia.org/wiki/Conjunctive_normal_form * or "disjunctive normal form" boolean logic: * https://en.wikipedia.org/wiki/Disjunctive_normal_form */ export const enum FilterExpressionMode { /** * Short form for conjunctive normal form. * Same as `conjunctiveNormalForm` */ CNF = "cnf", /** * Long form for conjunctive normal form. * Same as `CNF` */ conjunctiveNormalForm = "cnf", /** * Short form for disjunctive normal form. * Same as `disjunctiveNormalForm` */ DNF = "dnf", /** * Long form for disjunctive normal form. * Same as `DNF` */ disjunctiveNormalForm = "dnf" } /** * Enum containing the different operations that a filter can perform. */ export const enum FilterOperation { /** * Indicates that string-based values contains the given value, or that * collection-based values contain the given value */ contains = "contains", /** * Indicates that string-based values dose not contain the given value, or that * collection-based values do not contain the given value */ notContains = "not_contains", /** * Indicates that the row value is part of the given array of values */ in = "in", /** * Indicates that row value is not in the given array of values */ notIn = "not_in", /** * Filters for rows where the target field equals the value */ equal = "equal", /** * Filters for rows where the target field is not equal to the value */ notEqual = "not_equal", /** * Filters for rows where the value is greater than the given value */ greaterThan = "greater_than", /** * Filters for rows where the value is greater than the given value */ greaterThanOrEqual = "greater_than_or_equal", /** * Filters for rows where the value is less than the given value */ lessThan = "less_than", /** * Filters for rows where the value is less than the given value */ lessThanOrEqual = "less_than_or_equal", /** * Filters for rows where the string value starts with the given value */ startsWith = "starts_with", /** * Filters for rows where the string value ends with the given value */ endsWith = "ends_with" } /** * Object describing a single rule used in a filter. */ export type FilterRule = { field: string; value: string | number; operation: FilterOperation; }; /** * Group of rules used by this filter, it will interpreted either as a conjunction or disjunction, depending on the * {@link FilterExpressionMode} used at runtime. */ export type FilterClause = FilterRule[]; /** * A set of clauses that describe a filter. How it will be interpreted depends in the {@link FilterExpressionMode} used * at runtime. */ export type FilterExpression = FilterClause[]; /** * Class to process filters on Tables. * This class is meant to be used by filter workers, but it is safe to use on the main thread as well. * Creates a new instance and reconstructs the Heap, Memory Object and Table specified in the config object. * NOTE: Heap, MemoryBlock and Table classes are thread safe. * @param config - Configuration object. */ export class FilterProcessor { constructor(config: any); /** * Fetches the memory from this filter processor and invalidates all objects linked to it. * WARNING: This filter worker will not work after this function is called and before a new memory block is set. */ fetchMemory(): ArrayBuffer | SharedArrayBuffer; /** * Processes the rules in batches the size configures in the config object * @param config - Configuration object. */ process(config: any): void; } /** * Creates a {@link Table} instance and fills its contents from the specified local CSV file. * @param file - A file instance, representing the file to load. * @param heap - The heap where the loaded table will be stored. */ export function tableFromLocalCSV(file: File, heap: Heap): Table; /** * Creates a {@link Table} instance and fills its contents from the specified remote CSV file. * @param url - The URL from which the CSV file will be loaded. */ export function tableFromRemoteCSV(url: string): Promise
; /** * Class to read and write values of a row in a {@link ProxyTable}. * Constructs an instance of a row in the given table at the specified index. * Each Row instance automatically adds new properties with the names of the columns to its `fields` object for * easy access. * WARNING: String returned by a row will mutate when the row's address changes, if strings with constant values are * needed, either copy of the string or create a JS string from it by calling `toString` on it. * @param table - The table this row belongs to. * @param [index] - the row index at which this instance will read data. Defaults to 0. * @param [binary] - Should this row return binary strings. */ export class ProxyRow { constructor(table: ProxyTable, index?: number, binary?: boolean); /** * The size, in bytes, of a row in the table. */ size: number; /** * The table this row belongs to. */ table: Table; /** * An array containing the names of the columns in the table this row belongs to. */ columns: { name: string; size: number; offset: number; type: Type; }[]; /** * An object containing the column names as keys and their index in the table's header as their value. */ names: { [key: string]: number; }; /** * An array, ordeed by the order in which each field appears in the table's header, containing accessor objects for * the fields in this row. */ accessors: { column: string; getter: (...params: any[]) => any; setter: null; }[]; /** * An object containing properties to get and set the values for the fields in this row based on their column names. * NOTE: Setting values is not implemented yet. */ fields: any; /** * The internal pointer this row uses to access its memory. Changing the location of this pointer will result in * the contents of the row being updated. * WARNING: Setting the address of this pointer to a memory address that does not represent the beginning of a * row in a table will result in undefined behaviour. */ pointer: Pointer; /** * The row index this instance is currently pointing at. * Does not take into consideration the internal pointer address * to calculate the new row address so it's safe to use to reset the internal pointer address. */ index: number; } /** * Class that fetches the data from a source table based on the index numbers of another table, usually resulting from * a filter operation. * @param sourceTable - The table from which the values will be read. * @param indexTable - The table containing the indices to fetch. */ export class ProxyTable { constructor(sourceTable: Table, indexTable: Table); /** * Destroys this table instance and frees the memory associated with it. This method must be called when the memory * associated to this table is no longer needed to avoid memory leaks in kruda's internal memory management system. * WARNING: While this method destroys its index table, it does not destroy its source table. * DEV NOTE: Implementing a reference counting system could make it more intuitive and allow users to leave memory * management to kruda (although retaining and releasing instances would still be the user's responsibility). */ destroy(): void; /** * The table containing the indices to access the data from the source table. */ indexTable: Table; /** * The table which will be proxied using the indices in the index table. */ sourceTable: Table; /** * The header of the source data table. Contains column names, order in memory, original order and type information. */ header: Header; /** * The header of the index data table. Contains column names, order in memory, original order and type information. */ indexTableHeader: Header; /** * The total number of rows in this table. */ rowCount: number; /** * The memory block that contains the index table's layout and data. */ memory: MemoryBlock; /** * The memory block that contains the source data table's layout and data. */ sourceTableMemory: MemoryBlock; /** * The offset, in bytes, from the beginning of the index table to the row data. */ dataOffset: number; /** * The offset, in bytes, from the beginning of the source data table to the row data. */ sourceTableDataOffset: number; /** * Gets a new Row instance pointing at the row at the specified index. * NOTE: The returned row can be moved to point to a different row by changing its `index` property. * @param index - The index of the row to get the data from. * @param [row] - An optional row, belonging to this table, to reuse. Useful to reduce garbage collection. */ getRow(index: number, row?: ProxyRow): ProxyRow; /** * Gets a new Row instance pointing at the row at the specified index. The resulting row will return * {@link ByteString} instances for the column fields which are strings. ByteStrings are faster to work with but are * not replacements for JavaScript strings. * NOTE: The returned row can be moved to point to a different row by changing its `index` property. * @param index - The index of the row to get the data from. * @param [row] - An optional row, belonging to this table, to reuse. Useful to reduce garbage collection. */ getBinaryRow(index: number, row?: ProxyRow): ProxyRow; /** * Iterates through all the rows in this table and invokes the provided callback `itr` on each iteration. * WARNING: This function is designed to avoid garbage collection and improve performance so the row passed to the * `itr` callback is reused, the row cannot be stored as its contents will change. If you need to store unique rows * consider using the `getRow` method. * @param itr - Callback function to invoke for each row in this table. */ forEach(itr: (...params: any[]) => any): void; } /** * Class that represents a column in a {@link Header} * Constructs a Column by reading its properties from the offsets in the specified memory block. * @param memory - The memory to initialize this instance with * @param offset - The byte offset for the size, offset and type fields. * @param nameOffset - The byte offset for this column's name string. */ export class Column { constructor(memory: MemoryBlock, offset: number, nameOffset: number); /** * The name of this column. */ name: ByteStringBase; /** * The size in bytes of data entries in this column. */ size: number; /** * The offset in bytes for the start of the data this column represents. */ dataOffset: number; /** * The offset with respect to the beginning of each row for data entries in this column. */ offset: number; /** * The type for data entries in this column. */ type: Type; /** * The total byteLength of this column's description. */ byteLength: number; } /** * Different memory layouts for a table */ export const enum MemoryLayout { RELATIONAL = 0, COLUMNAR = 1 } /** * @property name - This column's name * @property type - The type of this column by name, index or Type instance. * @property [dataOffset] - The offset in bytes for the start of the data this column represents. * @property [offset] - The offset in bytes where the data in this column is in each row. * @property [length] - The maximum length of the column, if the type is `ByteString` */ export type ColumnDescriptor = { name: string; type: Type | string | number; dataOffset?: number; offset?: number; length?: number; }; /** * The length in bytes of a column's meta (without counting its name) */ export const kColumnMetaLength = 16; /** * @property columns - The columns in the table * @property rowCount - Current number of rows in the table. * @property rowLength - The length, in bytes, of a row in the table. * @property rowStep - The number of bytes a pointer needs to shift to point at the next/prev row. * @property dataLength - The total length, in bytes, of the data contained in the table. * @property layout - The layout for the data in this table */ export type HeaderDescriptor = { columns: ColumnDescriptor[]; rowCount: number; rowLength: number; rowStep: number; dataLength: number; layout: MemoryLayout; }; /** * The length in bytes of a header's meta (without the columns) */ export const kHeaderMetaLength = 28; /** * Class that represents the header of a {@link Table}. * Constructs an instance of a Header by reading its properties from the beginning of the specified memory block. * @param memory - The memory containing the table header. The table header must be at the beginning. */ export class Header { constructor(memory: MemoryBlock); /** * Different memory layouts for a table */ static memoryLayout: { [key: string]: MemoryLayout; }; /** * The length in bytes of a header's meta (without the columns) */ static headerMetaLength: number; /** * The length in bytes of a column's meta (without counting its name) */ static columnMetaLength: number; /** * Convenience function to build a header descriptor from an array of column descriptors. * @param columns - The columns to initialize the header with * @param [memoryLength = 0] - The length of the memory where the table will reside. Defaults to 0 * @param [layout] - The layout of the table. Defaults to RELATIONAL */ static descriptorFromColumns(columns: ColumnDescriptor[], memoryLength?: number, layout?: MemoryLayout): HeaderDescriptor; /** * Convenience function to build a binary header from an array of column descriptors. * @param columns - The columns to initialize the header with * @param [memoryLength = 0] - The length of the memory where the table will reside. Defaults to 0 * @param [layout] - The layout of the table. Defaults to RELATIONAL */ static binaryFromColumns(columns: ColumnDescriptor[], memoryLength?: number, layout?: MemoryLayout): ArrayBuffer; /** * Convenience function to build a binary buffer containing the header info from an object descriptor. * @param header - Object describing the properties of the header */ static buildBinaryHeader(header: HeaderDescriptor): ArrayBuffer; /** * The length, in bytes, of this header in memory. */ length: number; /** * The number of columns described in the header. */ columnCount: number; /** * The number of rows that the table linked to this header should contain. */ rowCount: number; /** * The normalized length, in bytes, of a single row in the table. */ rowLength: number; /** * The number of bytes a pointer needs to shift to move from one row to the next. */ rowStep: number; /** * The length, in bytes, of the data contained in the table this header is describing. */ dataLength: number; /** * The memory layout of the table. */ layout: MemoryLayout; /** * An array containing objects describing each of the columns described in this header. */ columns: Column[]; /** * Returns an object which contains the names of the columns described in this header as keys and the index of the * column within the `columns` array as their value. */ names: { [key: string]: number; }; /** * Modifies this header atomically the number of rows specified. * NOTE: This function does not change the underlying data storage or its contents. * @param count - The new number of rows for this table. */ setRowCount(count: number): number; /** * Modifies this header atomically to add the number of rows specified. * @param count - The number of rows to add */ addRows(count: number): number; } /** * Class to read and write values of a row in a {@link Table}. * Constructs an instance of a row in the given table at the specified index. * Each Row instance automatically adds new properties with the names of the columns to its `fields` object for * easy access. * WARNING: String returned by a row will mutate when the row's address changes, if strings with constant values are * needed, either copy of the string or create a JS string from it by calling `toString` on it. * @param table - The table this row belongs to. * @param [index] - the row index at which this instance will read data. Defaults to 0. * @param [binary] - Should this row return binary strings. */ export class Row { constructor(table: Table, index?: number, binary?: boolean); /** * The size, in bytes, of a row in the table. */ size: number; /** * The number of bytes the internal pointer shifts in order to move to the next/previous row in the data. */ step: number; /** * The table this row belongs to. */ table: Table; /** * An array containing the names of the columns in the table this row belongs to. */ columns: { name: string; size: number; offset: number; type: Type; }[]; /** * An object containing the column names as keys and their index in the table's header as their value. */ names: { [key: string]: number; }; /** * An array, ordeed by the order in which each field appears in the table's header, containing accessor objects for * the fields in this row. */ accessors: { column: string; getter: (...params: any[]) => any; setter: (arg0: any) => void; }[]; /** * An object containing properties to get and set the values for the fields in this row based on their column names. * NOTE: Setting values is not implemented yet. */ fields: any; /** * The internal pointer this row uses to access its memory. Changing the location of this pointer will result in * the contents of the row being updated. * WARNING: Setting the address of this pointer to a memory address that does not represent the beginning of a * row in a table will result in undefined behaviour. */ pointer: Pointer; /** * The row index this instance is currently pointing at. * Does not take into consideration the internal pointer address * to calculate the new row address so it's safe to use to reset the internal pointer address. */ index: number; } /** * Class that represents a table in binary memory. * @param memory - The MemoryBlock containing the table's data */ export class Table { constructor(memory: MemoryBlock); /** * Destroys this table instance and frees the memory associated with it. This method must be called when the memory * associated to this table is no longer needed to avoid memory leaks in kruda's internal memory management system. */ destroy(): void; /** * Different memory layouts for a table */ static memoryLayout: { [key: string]: MemoryLayout; }; /** * Crates a new empty Table with the specified columns in the supplied memory. The table will * be able to grow as big as the memory that contains it. * @param columns - The columns for the new Table * @param memory - The memory where the new Table will live * @param [layout] - The memory layout to use for the new table. Defaults to RELATIONAL */ static emptyFromColumns(columns: ColumnDescriptor[], memory: MemoryBlock, layout?: MemoryLayout): Table; /** * Crates a new empty Table with the specified header descriptor in the supplied memory. The table will * be able to grow as big as the memory that contains it. * @param header - The header descriptor tu use * @param memory - The memory where the new Table will live */ static emptyFromHeader(header: HeaderDescriptor, memory: MemoryBlock): Table; /** * Crates a new empty Table with the specified binary header in the supplied memory. The table will * be able to grow as big as the memory that contains it. * @param header - The binary header to use * @param memory - The memory where the new Table will live */ static emptyFromBinaryHeader(header: ArrayBuffer, memory: MemoryBlock): Table; /** * The header of this table. Contains column names, order in memory, original order and type information. */ header: Header; /** * The total number of rows in this table. */ rowCount: number; /** * The memory block that contains this table's layout and data. */ memory: MemoryBlock; /** * The offset, in bytes, from the beginning of this table to the row data. */ dataOffset: number; /** * Adds the specified number of rows to this table and returns the old row count. * NOTE: The memory in the new rows is NOT cleared before returning. * @param [count = 1] - The number of rows to add */ addRows(count?: number): number; /** * Adds the specified number of rows to this table and returns the old row count. * NOTE: The underlying memory store is not changed by this function. * @param count - The number of rows to add */ setRowCount(count: number): number; /** * Gets a new Row instance pointing at the row at the specified index. * NOTE: The returned row can be moved to point to a different row by changing its `index` property. * @param index - The index of the row to get the data from. * @param [row] - An optional row, belonging to this table, to reuse. Useful to reduce garbage collection. */ getRow(index: number, row?: Row): Row; /** * Gets a new Row instance pointing at the row at the specified index. The resulting row will return * {@link ByteString} instances for the column fields which are strings. ByteStrings are faster to work with but are * not replacements for JavaScript strings. * NOTE: The returned row can be moved to point to a different row by changing its `index` property. * @param index - The index of the row to get the data from. * @param [row] - An optional row, belonging to this table, to reuse. Useful to reduce garbage collection. */ getBinaryRow(index: number, row?: Row): Row; /** * Iterates through all the rows in this table and invokes the provided callback `itr` on each iteration. * WARNING: This function is designed to avoid garbage collection and improve performance so the row passed to the * `itr` callback is reused, the row cannot be stored as its contents will change. If you need to store unique rows * consider using the `getRow` method. * @param itr - Callback function to invoke for each row in this table. */ forEach(itr: (...params: any[]) => any): void; } /** * Base class for all byte string classes. Cannot be used directly. * Constructs a ByteString instance of the given size. * @param size - The maximum size of this string. */ export class ByteStringBase { constructor(size: number); size: number; buffer: ArrayBufferLike; length: number; address: number; /** * Utility function, converts this ByteString to a JS string instance. */ toString(): string; /** * Checks if two byte strings are equal. Case sensitive. * @param other - The string to test against. */ equals(other: ByteStringBase): boolean; /** * Checks if two byte strings are equal. Case insensitive. * @param other - The string to test against. */ equalsCase(other: ByteStringBase): boolean; /** * Checks if this byte strings contains another string. Case sensitive. * @param other - The string to test against. */ contains(other: ByteStringBase): boolean; /** * Checks if this byte strings contains another string. Case insensitive. * @param other - The string to test against. */ containsCase(other: ByteStringBase): boolean; /** * Fetches the character code at the specified index. * @param index - The index of the character to fetch. */ charCodeAt(index: number): number; } /** * ByteString implementation using pointers. If the underlying pointer changes location the contents of this string * are automatically updated to reflect the data contained at the new location. * Constructs a byte string instance backed by a Pointer. * @param pointer - The pointer to read the string data from. * @param [offset] - The offset, from the location of the pointer, to read the data from. Defaults to 0. * @param [size] - The maximum size of this string in bytes. Defaults to 255. */ export class ByteStringPtr { constructor(pointer: Pointer, offset?: number, size?: number); length: number; buffer: ArrayBufferLike; address: number; /** * Fetches the character code at the specified index. * @param index - The index of the character to fetch. */ charCodeAt(index: number): number; } /** * ByteString implementation using ArrayBuffers. This implementation is useful for quick off-heap strings. It also * guarantees that it will not change its contents without implicit user interaction. * Constructs a byte string backed by an ArrayBuffer. * @param buffer - The ArrayBuffer object where this string resides. * @param [address] - The offset, in bytes, within the buffer where the string resides. Defaults to 0. * @param [size] - The maximum size of this string in bytes. Defaults to 255. */ export class ByteStringBuffer { constructor(buffer: ArrayBufferLike, address?: number, size?: number); buffer: ArrayBufferLike; length: number; address: number; /** * Fetches the character code at the specified index. * @param index - The index of the character to fetch. */ charCodeAt(index: number): number; } export class _ByteString extends Type { /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } export const ByteString: _ByteString; /** * Binary type list. */ export const kBinaryTypes: Type[]; /** * Binary type map. */ export const kBinaryTypeMap: Map; /** * Base class for all vector classes that implements the convenience functions of the class. Cannot be used directly. * Constructs a VectorBase instance. * @param components - The number of components in the vector * @param type - The type of the components within this vector */ export class VectorBase extends Iterable { constructor(components: number, type: Type); /** * The number of dimensions in this vector. */ length: number; /** * The type of the components in this vector. */ type: Type; /** * Convenience property to access the first component of the vector */ x: number; /** * Convenience property to access the second component of the vector */ y: number; /** * Convenience property to access the third component of the vector */ z: number; /** * Convenience property to access the fourth component of the vector */ w: number; /** * Convenience property to access the first component of the vector */ r: number; /** * Convenience property to access the second component of the vector */ g: number; /** * Convenience property to access the third component of the vector */ b: number; /** * Convenience property to access the fourth component of the vector */ a: number; /** * Gets the value of this vector at the specified index. * @param index - The index of the value to get. */ getComponentAt(index: number): number; /** * Sets the value of this vector at the specified index. * @param index - The index of the value to set * @param value - The value to set. */ setComponentAt(index: number, value: number): void; /** * Utility function, converts this Vector to a JS string instance. */ toString(): string; /** * Default implementation of iterable protocol, to comply with arrays: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values */ values(): Iterator; } /** * Vector class that gets its data from an ArrayBuffer. * @param type - The type of the components in this vector * @param components - The number of components in the vector * @param buffer - The buffer from which the components will be read * @param [address] - The offset, in bytes, where the data resides within the buffer */ export class VectorBuffer { constructor(type: Type, components: number, buffer: ArrayBufferLike, address?: number); /** * Gets the value of this vector at the specified index. * @param index - The index of the value to get. */ getComponentAt(index: number): number; /** * Sets the value of this vector at the specified index. * @param index - The index of the value to set * @param value - The value to set. */ setComponentAt(index: number, value: number): void; } /** * Vector class implementation using pointers. If the underlying pointer changes location the contents of this vector * are automatically updated to reflect the data contained at the new location.. * @param type - The type of the components in this vector * @param components - The number of components in the vector * @param pointer - The pointer to read the vector data from. * @param [offset] - The offset, from the location of the pointer, to read the data from. Defaults to 0. */ export class VectorPtr { constructor(type: Type, components: number, pointer: Pointer, offset?: number); /** * Gets the value of this vector at the specified index. * @param index - The index of the value to get. */ getComponentAt(index: number): number; /** * Sets the value of this vector at the specified index. * @param index - The index of the value to set * @param value - The value to set. */ setComponentAt(index: number, value: number): void; } export class Vector extends Type { constructor(name: string, components: number, type: Type); /** * Creates a ByteString instance from a pointer. * @param pointer - The pointer to read the string data from. * @param [offset = 0] - The offset, from the location of the pointer, to read the data from. Defaults to 0. */ fromPointer(pointer: Pointer, offset?: number): VectorPtr; /** * Creates a Vector instance from an ArrayBuffer * @param buffer - The ArrayBuffer object where this vector resides. * @param [address = 0] - The offset, in bytes, within the buffer where the vector resides. Defaults to 0. */ fromBuffer(buffer: ArrayBufferLike, address?: number): VectorBuffer; /** * Creates a vector from another vector. * @param vector - The vector to copy during creation. */ fromVector(vector: ArrayLike): VectorBuffer; /** * Returns the name of this type */ name: string; /** * Returns the size, in bytes, of this type. */ byteSize: number; /** * Returns the size, in bits, of this type. */ bitSize: number; /** * Utility function to read a value of this type from memory. * @param view - The data view used to read the value * @param offset - The offset, in bytes, of the value to read */ get(view: DataView, offset: number): any; /** * Utility function to set the value of this type in memory. * @param view - The data view used to write the value * @param offset - The offset, in bytes, at which the value will be written. * @param value - The value to write. */ set(view: DataView, offset: number, value: any): void; } /** * Utility function to create a new Vector type, useful for * @param name - The name of the new vector type * @param components - The number of components for the new vector * @param type - The type of the element in this vector */ export function newVectorType(name: string, components: number, type: Type): Vector; export const Vec2: Vector; export const I32Vec2: Vector; export const U32Vec2: Vector; export const I16Vec2: Vector; export const U16Vec2: Vector; export const I8Vec2: Vector; export const U8Vec2: Vector; export const Vec3: Vector; export const I32Vec3: Vector; export const U32Vec3: Vector; export const I16Vec3: Vector; export const U16Vec3: Vector; export const I8Vec3: Vector; export const U8Vec3: Vector; export const Types: { isPrimitiveType: typeof isPrimitiveType; typeByName: typeof typeByName; sizeof: typeof sizeof; isType: typeof isType; Type: typeof Type; Int8: _Int8; Int16: _Int16; Int32: _Int32; Uint8: _Uint8; Uint16: _Uint16; Uint32: _Uint32; Float32: _Float32; Void: _Void; }; /** * Returns the estimated physical core count in this system. */ export function coreCount(): Promise; export type HeapSerialized = { buffer: ArrayBuffer; }; /** * Utility function to serialize a heap to be sent to another thread. * @param heap - Heap to serialize */ export function serializeHeap(heap: Heap): HeapSerialized; /** * Utility function to deserialize a heap * @param descriptor - Description to deserialize */ export function deserializeHeap(descriptor: HeapSerialized): Heap; export type MemoryBlockSerialized = { heap: HeapSerialized; address: number; size: number; }; /** * Utility function to serialize a memory block to be sent to another thread. * @param memory - The memory block to serialize */ export function serializeMemoryBlock(memory: MemoryBlock): MemoryBlockSerialized; /** * Utility function to deserialize a memory block * @param descriptor - Description of the memory block to deserialize. */ export function deserializeMemoryBlock(descriptor: MemoryBlockSerialized): MemoryBlock; export type TableSerialized = { memory: MemoryBlockSerialized; }; /** * Utility function to serialize a table to be sent to another thread. * @param table - Heap to serialize */ export function serializeTable(table: Table): TableSerialized; /** * Utility function to deserialize a table * @param descriptor - Description to deserialize */ export function deserializeTable(descriptor: TableSerialized): Table;