UNPKG

molstar

Version:

A comprehensive macromolecular library.

56 lines (55 loc) 2.2 kB
/** * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { ColumnHelpers } from '../../../../../mol-data/db'; import { parseInt as fastParseInt, parseFloat as fastParseFloat } from '../number-parser'; export function TokenColumnProvider(tokens) { return function (type) { return TokenColumn(tokens, type); }; } export function TokenColumn(tokens, schema) { var data = tokens.data, indices = tokens.indices, rowCount = tokens.count; var type = schema.valueType; var value = type === 'str' ? function (row) { return data.substring(indices[2 * row], indices[2 * row + 1]); } : type === 'int' ? function (row) { return fastParseInt(data, indices[2 * row], indices[2 * row + 1]) || 0; } : function (row) { return fastParseFloat(data, indices[2 * row], indices[2 * row + 1]) || 0; }; return { schema: schema, __array: void 0, isDefined: true, rowCount: rowCount, value: value, valueKind: function (row) { return 0 /* Column.ValueKind.Present */; }, toArray: function (params) { return ColumnHelpers.createAndFillArray(rowCount, value, params); }, areValuesEqual: areValuesEqualProvider(tokens) }; } export function areValuesEqualProvider(tokens) { var data = tokens.data, indices = tokens.indices; return function (rowA, rowB) { var aS = indices[2 * rowA], bS = indices[2 * rowB]; var len = indices[2 * rowA + 1] - aS; if (len !== indices[2 * rowB + 1] - bS) return false; for (var i = 0; i < len; i++) { if (data.charCodeAt(i + aS) !== data.charCodeAt(i + bS)) { return false; } } return true; }; } export function areTokensEmpty(tokens) { var count = tokens.count, indices = tokens.indices; for (var i = 0; i < count; ++i) { if (indices[2 * i] !== indices[2 * i + 1]) return false; } return true; }