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

More array column

parent b4b329be
No related branches found
No related tags found
No related merge requests found
......@@ -4,14 +4,15 @@
* @author David Sehnal <david.sehnal@gmail.com>
*/
export type ColumnType = typeof ColumnType.str | typeof ColumnType.int | typeof ColumnType.float | typeof ColumnType.vector | typeof ColumnType.matrix
export type ColumnType = typeof ColumnType.str | typeof ColumnType.pooledStr | typeof ColumnType.int | typeof ColumnType.float | typeof ColumnType.vector | typeof ColumnType.matrix
export namespace ColumnType {
export const str = { '@type': '' as string, kind: 'str' as 'str', isScalar: false };
export const int = { '@type': 0 as number, kind: 'int' as 'int', isScalar: true };
export const float = { '@type': 0 as number, kind: 'float' as 'float', isScalar: true };
export const vector = { '@type': [] as number[], kind: 'vector' as 'vector', isScalar: false };
export const matrix = { '@type': [] as number[][], kind: 'matrix' as 'matrix', isScalar: false };
export const str = { '@type': '' as string, kind: 'str' as 'str', isScalar: false, isString: true };
export const pooledStr = { '@type': '' as string, kind: 'pooled-str' as 'pooled-str', isScalar: false, isString: true };
export const int = { '@type': 0 as number, kind: 'int' as 'int', isScalar: true, isString: false };
export const float = { '@type': 0 as number, kind: 'float' as 'float', isScalar: true, isString: false };
export const vector = { '@type': [] as number[], kind: 'vector' as 'vector', isScalar: false, isString: false };
export const matrix = { '@type': [] as number[][], kind: 'matrix' as 'matrix', isScalar: false, isString: false };
}
export interface ToArrayParams {
......@@ -76,12 +77,10 @@ export function ArrayColumn<T extends ColumnType>({ array, type, isValueDefined
for (let i = 0, _i = end - start; i < _i; i++) ret[i] = array[start + i];
return ret;
},
stringEquals: isTyped
stringEquals: type.isScalar
? (row, value) => (array as any)[row] === +value
: type.kind === 'str'
: type.isString
? (row, value) => array[row] === value
: type.isScalar
? (row, value) => array[row] === '' + value
: (row, value) => false,
areValuesEqual: (rowA, rowB) => array[rowA] === array[rowB]
}
......
......@@ -42,6 +42,7 @@ export function FixedColumn<T extends ColumnType>(lines: Tokens, offset: number,
return parseFloatSkipLeadingWhitespace(data, s, s + width);
};
return {
'@type': type,
isDefined: true,
rowCount,
value,
......
......@@ -30,6 +30,7 @@ export function TokenColumn<T extends ColumnType>(tokens: Tokens, type: T): Colu
: row => fastParseFloat(data, indices[2 * row], indices[2 * row + 1]) || 0;
return {
'@type': type,
isDefined: true,
rowCount,
value,
......
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