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

Pooled string column

parent 135635ac
No related branches found
No related tags found
No related merge requests found
......@@ -5,10 +5,11 @@
*/
export type ArrayType = string[] | number[] | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array
export type ColumnType = typeof ColumnType.str | typeof ColumnType.int | typeof ColumnType.float
export type ColumnType = typeof ColumnType.str | typeof ColumnType.pooledStr | typeof ColumnType.int | typeof ColumnType.float
export namespace ColumnType {
export const str = { '@type': '' as string, kind: 'str' as 'str' };
export const pooledStr = { '@type': '' as string, kind: 'pooled-str' as 'pooled-str' };
export const int = { '@type': 0 as number, kind: 'int' as 'int' };
export const float = { '@type': 0 as number, kind: 'float' as 'float' };
}
......
......@@ -7,6 +7,7 @@
import { Column, ColumnType, createArray } from '../../column'
import { trimStr } from '../tokenizer'
import { parseIntSkipLeadingWhitespace, parseFloatSkipLeadingWhitespace } from '../number-parser'
import StringPool from '../../../../utils/short-string-pool'
export interface FixedColumnInfo {
data: string,
......@@ -28,12 +29,18 @@ function getArrayValues(value: (row: number) => any, target: any[], start: numbe
export function FixedColumn<T extends ColumnType>(info: FixedColumnInfo, offset: number, width: number, type: T): Column<T['@type']> {
const { data, lines, rowCount } = info;
const { kind } = type;
const pool = kind === 'pooled-str' ? StringPool.create() : void 0;
const value: Column<T['@type']>['value'] = kind === 'str' ? row => {
let s = lines[2 * row] + offset, e = s + width, le = lines[2 * row + 1];
if (s >= le) return '';
if (e > le) e = le;
return trimStr(data, s, e);
} : kind === 'pooled-str' ? row => {
let s = lines[2 * row] + offset, e = s + width, le = lines[2 * row + 1];
if (s >= le) return '';
if (e > le) e = le;
return StringPool.get(pool!, trimStr(data, s, e));
} : kind === 'int' ? row => {
const s = lines[2 * row] + offset, e = s + width;
return parseIntSkipLeadingWhitespace(data, s, e);
......
......@@ -116,8 +116,8 @@ function handleAtoms(state: State): Schema.Atoms {
const ret = {
count: state.numberOfAtoms,
residueNumber: col(0, 5, ColumnType.int),
residueName: col(5, 5, ColumnType.str),
atomName: col(10, 5, ColumnType.str),
residueName: col(5, 5, ColumnType.pooledStr),
atomName: col(10, 5, ColumnType.pooledStr),
atomNumber: col(15, 5, ColumnType.int),
x: col(pO, pW, ColumnType.float),
y: col(pO + pW, pW, ColumnType.float),
......
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