diff --git a/src/mol-data/int/impl/interval.ts b/src/mol-data/int/impl/interval.ts index fe293e0a0c013897a68b07321349a5e8277ee6e9..a1097c13f7d0acc5c1f377dd6a7a26c7264da656 100644 --- a/src/mol-data/int/impl/interval.ts +++ b/src/mol-data/int/impl/interval.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ @@ -17,6 +17,7 @@ export const min = Tuple.fst; export function max(i: Tuple) { return Tuple.snd(i) - 1; } export function size(i: Tuple) { return Tuple.snd(i) - Tuple.fst(i); } export const hashCode = Tuple.hashCode; +export const toString = Tuple.toString; export function has(int: Tuple, v: number) { return Tuple.fst(int) <= v && v < Tuple.snd(int); } /** Returns the index of `x` in `set` or -1 if not found. */ diff --git a/src/mol-data/int/impl/ordered-set.ts b/src/mol-data/int/impl/ordered-set.ts index 832a0c28147326c66ce82c4bc80e971489d4a22e..6ae89045174a32ad677106917253b245a0f4b168 100644 --- a/src/mol-data/int/impl/ordered-set.ts +++ b/src/mol-data/int/impl/ordered-set.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ @@ -36,6 +36,8 @@ export function end(set: OrderedSetImpl) { return I.is(set) ? I.end(set) : S.end export function hashCode(set: OrderedSetImpl) { return I.is(set) ? I.hashCode(set) : S.hashCode(set); } // TODO: possibly add more hash functions to allow for multilevel hashing. +export function toString(set: OrderedSetImpl) { return I.is(set) ? I.toString(set) : S.toString(set); } + export function areEqual(a: OrderedSetImpl, b: OrderedSetImpl) { if (I.is(a)) { if (I.is(b)) return I.areEqual(a, b); diff --git a/src/mol-data/int/impl/sorted-array.ts b/src/mol-data/int/impl/sorted-array.ts index 0e6336af2f8fdbf2e56713dcce86481cdfd0ab61..faa32048fca2e968542643436b8ca878dbfccc24 100644 --- a/src/mol-data/int/impl/sorted-array.ts +++ b/src/mol-data/int/impl/sorted-array.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ @@ -35,6 +35,11 @@ export function hashCode(xs: Nums) { if (s > 2) return hash4(s, xs[0], xs[s - 1], xs[s >> 1]); return hash3(s, xs[0], xs[s - 1]); } +export function toString(xs: Nums) { + const s = xs.length; + if (s > 5) return `[${xs[0]}, ${xs[1]}, ..., ${xs[s - 1]}], length ${s}`; + return `[${(xs as number[]).join(', ')}]`; +} /** Returns the index of `x` in `set` or -1 if not found. */ export function indexOf(xs: Nums, v: number) { diff --git a/src/mol-data/int/interval.ts b/src/mol-data/int/interval.ts index ef72450b05865a03ecbffc4562e06c81ada34f49..a192dbcccaba258dd4c08ed6f7dbbbdc6c449bdb 100644 --- a/src/mol-data/int/interval.ts +++ b/src/mol-data/int/interval.ts @@ -34,6 +34,8 @@ namespace Interval { export const size: <T extends number = number>(interval: Interval<T>) => number = Impl.size as any; /** Hash code describing the interval */ export const hashCode: <T extends number = number>(interval: Interval<T>) => number = Impl.hashCode as any; + /** String representation of the interval */ + export const toString: <T extends number = number>(interval: Interval<T>) => string = Impl.toString as any; /** Test if two intervals are identical */ export const areEqual: <T extends number = number>(a: Interval<T>, b: Interval<T>) => boolean = Impl.areEqual as any; diff --git a/src/mol-data/int/ordered-set.ts b/src/mol-data/int/ordered-set.ts index 4ad91e171f6a8171b80535875fb07e42dd67230b..7f671e22a715fb6c26563a6fe39b06d6e49cf2da 100644 --- a/src/mol-data/int/ordered-set.ts +++ b/src/mol-data/int/ordered-set.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ @@ -8,7 +8,6 @@ import * as Base from './impl/ordered-set' import Interval from './interval' import SortedArray from './sorted-array'; -/** test */ namespace OrderedSet { export const Empty: OrderedSet = Base.Empty as any; export const ofSingleton: <T extends number = number>(value: T) => OrderedSet<T> = Base.ofSingleton as any; @@ -62,10 +61,12 @@ namespace OrderedSet { OrderedSet.forEach(set, v => array.push(v)) return array } + + export function toString<T extends number = number>(set: OrderedSet<T>): string { + return Base.toString(set) + } } -/** Represents bla */ type OrderedSet<T extends number = number> = SortedArray<T> | Interval<T> - export default OrderedSet \ No newline at end of file diff --git a/src/mol-data/int/sorted-array.ts b/src/mol-data/int/sorted-array.ts index cf0f5d11e09470a4b520cb00707faf4e7f034ea3..bd1c202b03c30a61865b902c305583ccb452cbed 100644 --- a/src/mol-data/int/sorted-array.ts +++ b/src/mol-data/int/sorted-array.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ @@ -31,6 +31,7 @@ namespace SortedArray { export const max: <T extends number = number>(array: SortedArray<T>) => T = Impl.max as any; export const size: <T extends number = number>(array: SortedArray<T>) => number = Impl.size as any; export const hashCode: <T extends number = number>(array: SortedArray<T>) => number = Impl.hashCode as any; + export const toString: <T extends number = number>(array: SortedArray<T>) => string = Impl.toString as any; export const areEqual: <T extends number = number>(a: SortedArray<T>, b: SortedArray<T>) => boolean = Impl.areEqual as any; export const areIntersecting: <T extends number = number>(a: SortedArray<T>, b: SortedArray<T>) => boolean = Impl.areIntersecting as any; diff --git a/src/mol-data/int/tuple.ts b/src/mol-data/int/tuple.ts index 7967f45cff1e784ec19e0db7a32b86b6e1633dcc..215ed92c905281a653430ac22b6eccbd0acb9052 100644 --- a/src/mol-data/int/tuple.ts +++ b/src/mol-data/int/tuple.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ @@ -73,6 +73,11 @@ namespace IntTuple { _float64[0] = t as any; return hash2(_int32[0], _int32[1]); } + + export function toString(t: IntTuple) { + _float64[0] = t as any; + return `(${_int32[0]}, ${_int32[1]})`; + } } export default IntTuple \ No newline at end of file