|
@@ -10,7 +10,7 @@ import { Tensor as Tensors } from 'mol-math/linear-algebra'
|
|
|
|
|
|
interface Column<T> {
|
|
interface Column<T> {
|
|
readonly schema: Column.Schema,
|
|
readonly schema: Column.Schema,
|
|
- readonly '@array': ArrayLike<any> | undefined,
|
|
|
|
|
|
+ readonly __array: ArrayLike<any> | undefined,
|
|
|
|
|
|
readonly isDefined: boolean,
|
|
readonly isDefined: boolean,
|
|
readonly rowCount: number,
|
|
readonly rowCount: number,
|
|
@@ -159,14 +159,14 @@ namespace Column {
|
|
|
|
|
|
/** Makes the column backed by an array. Useful for columns that are accessed often. */
|
|
/** Makes the column backed by an array. Useful for columns that are accessed often. */
|
|
export function asArrayColumn<T>(c: Column<T>, array?: ArrayCtor<T>): Column<T> {
|
|
export function asArrayColumn<T>(c: Column<T>, array?: ArrayCtor<T>): Column<T> {
|
|
- if (c['@array']) return c;
|
|
|
|
|
|
+ if (c.__array) return c;
|
|
if (!c.isDefined) return Undefined(c.rowCount, c.schema) as any as Column<T>;
|
|
if (!c.isDefined) return Undefined(c.rowCount, c.schema) as any as Column<T>;
|
|
return arrayColumn({ array: c.toArray({ array }), schema: c.schema, valueKind: c.valueKind });
|
|
return arrayColumn({ array: c.toArray({ array }), schema: c.schema, valueKind: c.valueKind });
|
|
}
|
|
}
|
|
|
|
|
|
export function copyToArray<T extends number>(c: Column<T>, array: { [k: number]: T, length: number }, offset = 0) {
|
|
export function copyToArray<T extends number>(c: Column<T>, array: { [k: number]: T, length: number }, offset = 0) {
|
|
if (!c.isDefined) return;
|
|
if (!c.isDefined) return;
|
|
- const cArray = c['@array']
|
|
|
|
|
|
+ const cArray = c.__array
|
|
if (cArray) {
|
|
if (cArray) {
|
|
for (let i = 0, _i = cArray.length; i < _i; i++) array[offset + i] = cArray[i];
|
|
for (let i = 0, _i = cArray.length; i < _i; i++) array[offset + i] = cArray[i];
|
|
} else {
|
|
} else {
|
|
@@ -200,7 +200,7 @@ function constColumn<T extends Column.Schema>(v: T['T'], rowCount: number, schem
|
|
const value: Column<T['T']>['value'] = row => v;
|
|
const value: Column<T['T']>['value'] = row => v;
|
|
return {
|
|
return {
|
|
schema: schema,
|
|
schema: schema,
|
|
- '@array': void 0,
|
|
|
|
|
|
+ __array: void 0,
|
|
isDefined: valueKind === Column.ValueKind.Present,
|
|
isDefined: valueKind === Column.ValueKind.Present,
|
|
rowCount,
|
|
rowCount,
|
|
value,
|
|
value,
|
|
@@ -217,7 +217,7 @@ function constColumn<T extends Column.Schema>(v: T['T'], rowCount: number, schem
|
|
function lambdaColumn<T extends Column.Schema>({ value, valueKind, rowCount, schema }: Column.LambdaSpec<T>): Column<T['T']> {
|
|
function lambdaColumn<T extends Column.Schema>({ value, valueKind, rowCount, schema }: Column.LambdaSpec<T>): Column<T['T']> {
|
|
return {
|
|
return {
|
|
schema: schema,
|
|
schema: schema,
|
|
- '@array': void 0,
|
|
|
|
|
|
+ __array: void 0,
|
|
isDefined: true,
|
|
isDefined: true,
|
|
rowCount,
|
|
rowCount,
|
|
value,
|
|
value,
|
|
@@ -240,7 +240,7 @@ function arrayColumn<T extends Column.Schema>({ array, schema, valueKind }: Colu
|
|
const isTyped = ColumnHelpers.isTypedArray(array);
|
|
const isTyped = ColumnHelpers.isTypedArray(array);
|
|
return {
|
|
return {
|
|
schema: schema,
|
|
schema: schema,
|
|
- '@array': array,
|
|
|
|
|
|
+ __array: array,
|
|
isDefined: true,
|
|
isDefined: true,
|
|
rowCount,
|
|
rowCount,
|
|
value,
|
|
value,
|
|
@@ -271,12 +271,12 @@ function arrayColumn<T extends Column.Schema>({ array, schema, valueKind }: Colu
|
|
function windowColumn<T>(column: Column<T>, start: number, end: number) {
|
|
function windowColumn<T>(column: Column<T>, start: number, end: number) {
|
|
if (!column.isDefined) return Column.Undefined(end - start, column.schema);
|
|
if (!column.isDefined) return Column.Undefined(end - start, column.schema);
|
|
if (start === 0 && end === column.rowCount) return column;
|
|
if (start === 0 && end === column.rowCount) return column;
|
|
- if (!!column['@array'] && ColumnHelpers.isTypedArray(column['@array'])) return windowTyped(column, start, end);
|
|
|
|
|
|
+ if (!!column.__array && ColumnHelpers.isTypedArray(column.__array)) return windowTyped(column, start, end);
|
|
return windowFull(column, start, end);
|
|
return windowFull(column, start, end);
|
|
}
|
|
}
|
|
|
|
|
|
function windowTyped<T>(c: Column<T>, start: number, end: number): Column<T> {
|
|
function windowTyped<T>(c: Column<T>, start: number, end: number): Column<T> {
|
|
- const array = ColumnHelpers.typedArrayWindow(c['@array'], { start, end });
|
|
|
|
|
|
+ const array = ColumnHelpers.typedArrayWindow(c.__array, { start, end });
|
|
return arrayColumn({ array, schema: c.schema, valueKind: c.valueKind }) as any;
|
|
return arrayColumn({ array, schema: c.schema, valueKind: c.valueKind }) as any;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -286,7 +286,7 @@ function windowFull<T>(c: Column<T>, start: number, end: number): Column<T> {
|
|
const rowCount = end - start;
|
|
const rowCount = end - start;
|
|
return {
|
|
return {
|
|
schema: c.schema,
|
|
schema: c.schema,
|
|
- '@array': void 0,
|
|
|
|
|
|
+ __array: void 0,
|
|
isDefined: c.isDefined,
|
|
isDefined: c.isDefined,
|
|
rowCount,
|
|
rowCount,
|
|
value,
|
|
value,
|
|
@@ -311,12 +311,12 @@ function isIdentity(map: ArrayLike<number>, rowCount: number) {
|
|
function columnView<T>(c: Column<T>, map: ArrayLike<number>, checkIdentity: boolean): Column<T> {
|
|
function columnView<T>(c: Column<T>, map: ArrayLike<number>, checkIdentity: boolean): Column<T> {
|
|
if (!c.isDefined) return c;
|
|
if (!c.isDefined) return c;
|
|
if (checkIdentity && isIdentity(map, c.rowCount)) return c;
|
|
if (checkIdentity && isIdentity(map, c.rowCount)) return c;
|
|
- if (!!c['@array']) return arrayView(c, map);
|
|
|
|
|
|
+ if (!!c.__array) return arrayView(c, map);
|
|
return viewFull(c, map);
|
|
return viewFull(c, map);
|
|
}
|
|
}
|
|
|
|
|
|
function arrayView<T>(c: Column<T>, map: ArrayLike<number>): Column<T> {
|
|
function arrayView<T>(c: Column<T>, map: ArrayLike<number>): Column<T> {
|
|
- const array = c['@array']!;
|
|
|
|
|
|
+ const array = c.__array!;
|
|
const ret = new (array as any).constructor(map.length);
|
|
const ret = new (array as any).constructor(map.length);
|
|
for (let i = 0, _i = map.length; i < _i; i++) ret[i] = array[map[i]];
|
|
for (let i = 0, _i = map.length; i < _i; i++) ret[i] = array[map[i]];
|
|
return arrayColumn({ array: ret, schema: c.schema, valueKind: c.valueKind });
|
|
return arrayColumn({ array: ret, schema: c.schema, valueKind: c.valueKind });
|
|
@@ -328,7 +328,7 @@ function viewFull<T>(c: Column<T>, map: ArrayLike<number>): Column<T> {
|
|
const rowCount = map.length;
|
|
const rowCount = map.length;
|
|
return {
|
|
return {
|
|
schema: c.schema,
|
|
schema: c.schema,
|
|
- '@array': void 0,
|
|
|
|
|
|
+ __array: void 0,
|
|
isDefined: c.isDefined,
|
|
isDefined: c.isDefined,
|
|
rowCount,
|
|
rowCount,
|
|
value,
|
|
value,
|
|
@@ -351,12 +351,12 @@ function mapToArrayImpl<T, S>(c: Column<T>, f: (v: T) => S, ctor: Column.ArrayCt
|
|
function areColumnsEqual(a: Column<any>, b: Column<any>) {
|
|
function areColumnsEqual(a: Column<any>, b: Column<any>) {
|
|
if (a === b) return true;
|
|
if (a === b) return true;
|
|
if (a.rowCount !== b.rowCount || a.isDefined !== b.isDefined || a.schema.valueType !== b.schema.valueType) return false;
|
|
if (a.rowCount !== b.rowCount || a.isDefined !== b.isDefined || a.schema.valueType !== b.schema.valueType) return false;
|
|
- if (!!a['@array'] && !!b['@array']) return areArraysEqual(a, b);
|
|
|
|
|
|
+ if (!!a.__array && !!b.__array) return areArraysEqual(a, b);
|
|
return areValuesEqual(a, b);
|
|
return areValuesEqual(a, b);
|
|
}
|
|
}
|
|
|
|
|
|
function areArraysEqual(a: Column<any>, b: Column<any>) {
|
|
function areArraysEqual(a: Column<any>, b: Column<any>) {
|
|
- const xs = a['@array']!, ys = b['@array']!;
|
|
|
|
|
|
+ const xs = a.__array!, ys = b.__array!;
|
|
for (let i = 0, _i = a.rowCount; i < _i; i++) {
|
|
for (let i = 0, _i = a.rowCount; i < _i; i++) {
|
|
if (xs[i] !== ys[i]) return false;
|
|
if (xs[i] !== ys[i]) return false;
|
|
}
|
|
}
|