@uncharted.software/kruda

0.1.0

Reading Data

Loading a data into a table.

Class that represents the header of a Table. Constructs an instance of a Header by reading its properties from the beginning of the specified memory block.

new Header(memory: MemoryBlock)
Parameters
memory (MemoryBlock) The memory containing the table header. The table header must be at the beginning.
Static Members
memoryLayout
headerMetaLength
columnMetaLength
descriptorFromColumns(columns, memoryLength = 0, layout = Header.memoryLayout.RELATIONAL)
binaryFromColumns(columns, memoryLength = 0, layout = Header.memoryLayout.RELATIONAL)
buildBinaryHeader(header)
Instance Members
length
columnCount
rowCount
rowLength
rowStep
dataLength
layout
columns
names
addRows(count)

Table

Class that represents a table in binary memory.

new Table(memory: MemoryBlock)
Parameters
memory (MemoryBlock) The MemoryBlock containing the table's data
Static Members
memoryLayout
emptyFromColumns(columns, memory, layout = Header.memoryLayout.RELATIONAL)
emptyFromHeader(header, memory)
emptyFromBinaryHeader(header, memory)
Instance Members
destroy()
header
rowCount
memory
dataOffset
addRows(count)
getRow(index, row = new Row(this,index))
getBinaryRow(index, row = new Row(this,index,true))
forEach(itr)

Row

Class to read and write values of a row in a 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.

new Row(table: Table, index: number?, binary: boolean?)
Parameters
table (Table) The table this row belongs to.
index (number?) the row index at which this instance will read data. Defaults to 0.
binary (boolean?) Should this row return binary strings.
Instance Members
size
step
table
columns
names
accessors
fields
pointer
index

ProxyTable

Class that fetches the data from a source table based on the index numbers of another table, usually resulting from a filter operation.

new ProxyTable(sourceTable: Table, indexTable: Table)
Parameters
sourceTable (Table) The table from which the values will be read.
indexTable (Table) The table containing the indices to fetch.
Instance Members
destroy()
indexTable
sourceTable
header
indexTableHeader
rowCount
memory
sourceTableMemory
dataOffset
sourceTableDataOffset
getRow(index, row = new ProxyRow(this,index))
getBinaryRow(index, row = new ProxyRow(this,index,true))
forEach(itr)

ProxyRow

Class to read and write values of a row in a 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.

new ProxyRow(table: ProxyTable, index: number?, binary: boolean?)
Parameters
table (ProxyTable) The table this row belongs to.
index (number?) the row index at which this instance will read data. Defaults to 0.
binary (boolean?) Should this row return binary strings.
Instance Members
size
table
columns
names
accessors
fields
pointer
index

tableFromLocalCSV

Creates a Table instance and fills its contents from the specified local CSV file.

tableFromLocalCSV(file: File, heap: Heap): Table
Parameters
file (File) A file instance, representing the file to load.
heap (Heap) The heap where the loaded table will be stored.
Returns
Table:

Manipulating Data

Filtering, aggregation, etc.

Filter

Class to create and run filters on tables. Creates a Filter instance bound to the specified table.

new Filter(table: Table, workerCount: number?, heap: Heap?)
Parameters
table (Table) The table this filter will be bound to.
workerCount (number?) The number of workers to spawn, should be the same as physical cores in the system, defaults to automatically detected.
heap (Heap?) The heap to use to allocate the filter results memory, defaults to using the same heap where the table is allocated.
Static Members
rowIndexResult
Instance Members
resultRowSize
resultDescription
resultFieldForColumn(columnName = null)
resultFieldForColumnIndex(columnIndex = null)
run(rules, mode = FilterExpressionMode.DNF)

FilterProcessor

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.

new FilterProcessor(config: ({heapBuffer: ArrayBufferLike, tableAddress: number, tableSize: number} | {}))
Parameters
config (({heapBuffer: ArrayBufferLike, tableAddress: number, tableSize: number} | {})) Configuration object.
Instance Members
setMemory(config)
fetchMemory()
process(config)

FilterExpression

A set of clauses that describe a filter. How it will be interpreted depends in the FilterExpressionMode used at runtime.

FilterExpression

Type: Array<FilterClause>

FilterClause

Group of rules used by this filter, it will interpreted either as a conjunction or disjunction, depending on the FilterExpressionMode used at runtime.

FilterClause

Type: Array<FilterRule>

FilterRule

Object describing a single rule used in a filter.

FilterRule

Type: Object

Properties
field (string)
value ((string | number))
operation (FilterOperation)

FilterOperation

Enum containing the different operations that a filter can perform.

FilterOperation
Static Members
contains
notContains
in
notIn
equal
notEqual
greaterThan
greaterThanOrEqual
lessThan
lessThanOrEqual
startsWith
endsWith

FilterExpressionMode

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

FilterExpressionMode
Static Members
CNF
conjunctiveNormalForm
DNF
disjunctiveNormalForm

Byte Strings

ByteString

ByteString

Type: _ByteString

Static Members
new(arg1, arg2 = 0, size = 255)
new(arg1, arg2 = 0, size = 255)
fromPointer(pointer, offset = 0, size = 255)
fromPointer(pointer, offset = 0, size = 255)
fromBuffer(buffer, address = 0, size = 255)
fromBuffer(buffer, address = 0, size = 255)
fromString(str)
fromString(str)

ByteStringBase

Base class for all byte string classes. Cannot be used directly. Constructs a ByteString instance of the given size.

new ByteStringBase(size: number)
Parameters
size (number) The maximum size of this string.
Instance Members
size
buffer
length
address
toString()
equals(other)
equalsCase(other)
contains(other)
containsCase(other)
charCodeAt(index)

ByteStringPtr

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.

new ByteStringPtr(pointer: Pointer, offset: number?, size: number?)
Parameters
pointer (Pointer) The pointer to read the string data from.
offset (number?) The offset, from the location of the pointer, to read the data from. Defaults to 0.
size (number?) The maximum size of this string in bytes. Defaults to 255.
Instance Members
length
buffer
address
charCodeAt(index)

ByteStringBuffer

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.

new ByteStringBuffer(buffer: ArrayBufferLike, address: number?, size: number?)
Parameters
buffer (ArrayBufferLike) The ArrayBuffer object where this string resides.
address (number?) The offset, in bytes, within the buffer where the string resides. Defaults to 0.
size (number?) The maximum size of this string in bytes. Defaults to 255.
Instance Members
buffer
length
address
charCodeAt(index)

Types

Type base class, utilities and primitive type definitions.

Types

Types

Type: Object

Properties
isPrimitiveType (Class<isPrimitiveType>)
typeByName (Class<typeByName>)
sizeof (Class<sizeof>)
isType (Class<isType>)
Type (Class<Type>)
Int8 (_Int8)
Int16 (_Int16)
Int32 (_Int32)
Uint8 (_Uint8)
Uint16 (_Uint16)
Uint32 (_Uint32)
Float32 (_Float32)
Void (_Void)

Type

Creates a new type instance. In DEBUG mode performs checks if the bit and byte sizes are consistent.

new Type(name: string, byteSize: number, bitSize: number)
Parameters
name (string) The name of the type to create
byteSize (number) Size in bytes of this type
bitSize (number) Size in bits of this type, must be x8 bigger than byteSize
Static Members
sizeOf(t)
isType(t)
isPrimitive(t)
getTypeByName(name)
Instance Members
name
byteSize
bitSize
get(view, offset)
set(view, offset, value)

isType

Utility function, the same as Type.isType

isType(t: Type): boolean
Parameters
t (Type) The type to inspect
Returns
boolean:

isPrimitiveType

Utility function, the same as Type.isPrimitive

isPrimitiveType(t: Type): boolean
Parameters
t (Type) The type to inspect
Returns
boolean:

sizeof

Utility function, the same as Type.sizeOf

sizeof(t: Type): number
Parameters
t (Type) The type to inspect
Returns
number:

typeByName

Utility function, the same as Type.getTypeByName

typeByName(name: string): Type
Parameters
name (string) The name of the type to look for.
Returns
Type:

Int8

Int8

Type: _Int8

Int16

Int16

Type: _Int16

Int32

Int32

Type: _Int32

Uint8

Uint8

Type: _Uint8

Uint16

Uint16

Type: _Uint16

Uint32

Uint32

Type: _Uint32

Float32

Float32

Type: _Float32

Void

Void

Type: _Void

Core

Classes dedicated to memory access/management.

Heap

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.

new Heap(buffer: (ArrayBuffer | SharedArrayBuffer | number))
Parameters
buffer ((ArrayBuffer | SharedArrayBuffer | number)) The buffer to use or the size in bytes to allocate.
Static Members
sizeOf1KB
sizeOf1MB
sizeOf1GB
maxHeapSize
maxAllocSize
Instance Members
buffer
shared
dataView
size
usedMemory
freeMemory
allocOffset
malloc(size)
calloc(size)
free(memory)
shrink(memory, size)

MemoryBlock

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.

new MemoryBlock(heap: Heap, address: number, size: number)
Parameters
heap (Heap) The heap which will contain the memory.
address (number) The byte address of the beginning of the memory.
size (number) The size, in bytes, of this memory block.
Instance Members
address
heap
buffer
size
dataView
free()

Pointer

This class represents a position in a memory block.

new Pointer(memory: (Heap | MemoryBlock), address: number?, type: Type?)
Parameters
memory ((Heap | MemoryBlock)) The memory to which this Pointer will be bound to.
address (number?) The address of this pointer relative to the memory it is bound to.
type (Type?) The type of this pointer, defaults to Uint8.
Static Members
copy(other)
Instance Members
memory
view
address
type
value
castValue(type)
move(offset)
getValueAt(offset)
setValueAt(offset, value)
castValueAt(offset, type)
getInt8(offset)
getInt16(offset)
getInt32(offset)
getUint8(offset)
getUint16(offset)
getUint32(offset)
getFloat32(offset)

DSBIN

DS BIN files utilities.

DSBINLoader

Multi-threaded DSBIN file loader.

new DSBINLoader()
Static Members
loadFromFile(file, heap)
loadFromURL(url, heap)

DSBINInflate

Utility class to inflate zlib compressed ArrayBuffers into a custom ArrayBuffer, could be a SharedArrayBuffer.

new DSBINInflate(outputBuffer: Uint8Array, size: number?)
Parameters
outputBuffer (Uint8Array) Buffer where the uncompressed data will be written.
size (number?) The expected final size of the uncompressed data. Defaults to the full size of outputBuffer
Static Members
inflate(inputBuffer, outputBuffer, size = outputBuffer.length)
Instance Members
onEnd(status)

Misc

Uncategorized or undocumented objects.

IntTypedArray

IntTypedArray

Type: (Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray)

Atomize

Simple wrapper to provide atomics-like functionality in systems that lack the functionality.

Atomize

Type: (Atomics | AtomicsLike)

AtomicsLike

Simple stubbing for Atomics. WARNING: Does not implement any kind of synchronization.

new AtomicsLike()
Instance Members
add(typedArray, index, value)
and(typedArray, index, value)
compareExchange(typedArray, index, expectedValue, replacementValue)
exchange(typedArray, index, value)
isLockFree(size)
load(typedArray, index)
notify(typedArray, index, count)
or(typedArray, index, value)
store(typedArray, index, value)
sub(typedArray, index, value)
wait(typedArray, index, value, timeout)
xor(typedArray, index, value)

coreCount

Returns the estimated physical core count in this system.

coreCount(): Promise<number>
Returns
Promise<number>:

_Int8

new _Int8()

Extends Type

_Int16

new _Int16()

Extends Type

_Int32

new _Int32()

Extends Type

_Uint8

new _Uint8()

Extends Type

_Uint16

new _Uint16()

Extends Type

_Uint32

new _Uint32()

Extends Type

_Float32

new _Float32()

Extends Type

_Void

Void type (not to be confused with the void value.

new _Void()

Extends Type

tableFromRemoteCSV

Creates a Table instance and fills its contents from the specified remote CSV file.

tableFromRemoteCSV(url: string): Promise<Table>
Parameters
url (string) The URL from which the CSV file will be loaded.
Returns
Promise<Table>:

Column

Class that represents a column in a Header Constructs a Column by reading its properties from the offsets in the specified memory block.

new Column(memory: MemoryBlock, offset: number, nameOffset: number)
Parameters
memory (MemoryBlock) The memory to initialize this instance with
offset (number) The byte offset for the size, offset and type fields.
nameOffset (number) The byte offset for this column's name string.
Instance Members
name
size
dataOffset
offset
type
byteLength

kMemoryLayout

RELATIONAL: 0 COLUMNAR: 1

kMemoryLayout

Type: (0 | 1)

kMemoryLayout

Different memory layouts for a table

kMemoryLayout

Type: Object<string, MemoryLayout>

kColumnMetaLength

kColumnMetaLength

Type: Object

Properties
name (string) : This column's name
type ((Type | string | number)) : The type of this column by name, index or Type instance.
dataOffset (number?) : The offset in bytes for the start of the data this column represents.
offset (number?) : The offset in bytes where the data in this column is in each row.
length (number?) : The maximum length of the column, if the type is ByteString

kColumnMetaLength

The length in bytes of a column's meta (without counting its name)

kColumnMetaLength

Type: number

kHeaderMetaLength

kHeaderMetaLength

Type: Object

Properties
columns (Array<ColumnDescriptor>) : The columns in the table
rowCount (number) : Current number of rows in the table.
rowLength (number) : The length, in bytes, of a row in the table.
rowStep (number) : The number of bytes a pointer needs to shift to point at the next/prev row.
dataLength (number) : The total length, in bytes, of the data contained in the table.
layout (MemoryLayout) : The layout for the data in this table

kHeaderMetaLength

The length in bytes of a header's meta (without the columns)

kHeaderMetaLength

Type: number

_ByteString

ByteString type

new _ByteString()

Extends Type

kBinaryTypes

Binary type list.

kBinaryTypes

Type: Array<Type>

kBinaryTypeMap

Binary type map.

kBinaryTypeMap

Type: Map<Type, number>

VectorBase

Base class for all vector classes that implements the convenience functions of the class. Cannot be used directly. Constructs a VectorBase instance.

new VectorBase(components: number)
Parameters
components (number) The number of components in the vector
Instance Members
length
x
y
z
w
r
g
b
a
getComponentAt(index)
setComponentAt(index, value)
toString()

VectorBuffer

Vector class that gets its data from an ArrayBuffer.

new VectorBuffer(type: Type, components: number, buffer: ArrayBufferLike, address: number?)
Parameters
type (Type) The type of the components in this vector
components (number) The number of components in the vector
buffer (ArrayBufferLike) The buffer from which the components will be read
address (number?) The offset, in bytes, where the data resides within the buffer
Instance Members
getComponentAt(index)
setComponentAt(index, value)

_Vector

_Vector type

new _Vector(name: string, type: Type, components: number)

Extends Type

Parameters
name (string) The name of the new vector type
type (Type) The type of the element in this vector
components (number) The number of components for the new vector