Skip to content
Snippets Groups Projects
Commit 1aa995df authored by David Sehnal's avatar David Sehnal
Browse files

column map

parent a312f3e7
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,10 @@ describe('column', () => {
it('permutation', () => {
expect(Column.permutation(arr, [1, 0, 3, 2]).toArray()).toEqual([2, 1, 4, 3]);
});
it('map to array', () => {
expect(Column.mapToArray(arrWindow, x => x + 1)).toEqual([3, 4]);
});
})
describe('table', () => {
......
......@@ -94,6 +94,10 @@ namespace Column {
return createFirstIndexMapOfColumn(column);
}
export function mapToArray<T, S>(column: Column<T>, f: (v: T) => S, ctor?: { new(size: number): ArrayLike<number> }): ArrayLike<S> {
return mapToArrayImpl(column, f, ctor || Array);
}
/** Makes the column backned by an array. Useful for columns that accessed often. */
export function asArrayColumn<T>(c: Column<T>, array?: ToArrayParams['array']): Column<T> {
if (c['@array']) return c;
......@@ -257,6 +261,12 @@ function permutationFull<T>(c: Column<T>, map: ArrayLike<number>): Column<T> {
};
}
function mapToArrayImpl<T, S>(c: Column<T>, f: (v: T) => S, ctor: { new(size: number): ArrayLike<number> }): ArrayLike<S> {
const ret = new ctor(c.rowCount) as any;
for (let i = 0, _i = c.rowCount; i < _i; i++) ret[i] = f(c.value(i));
return ret;
}
export namespace ColumnHelpers {
export function getArrayBounds(rowCount: number, params?: Column.ToArrayParams) {
const start = params && typeof params.start !== 'undefined' ? Math.max(Math.min(params.start, rowCount - 1), 0) : 0;
......
......@@ -21,10 +21,7 @@ export const AtomsSchema = {
label_alt_id: mmCIF.atom_site.label_alt_id,
pdbx_formal_charge: mmCIF.atom_site.pdbx_formal_charge,
occupancy: mmCIF.atom_site.occupancy,
B_iso_or_equiv: mmCIF.atom_site.B_iso_or_equiv,
key: Column.Type.int,
source_row: Column.Type.int,
B_iso_or_equiv: mmCIF.atom_site.B_iso_or_equiv
};
export interface Atoms extends Table<typeof AtomsSchema> { }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment