From 08bb0a36d5047fcee8a53573b5685b582b5782cd Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Fri, 27 Oct 2017 00:28:24 +0200 Subject: [PATCH] naming things --- src/mol-base/_spec/collections.spec.ts | 24 +++++++++---------- src/mol-base/collections/ordered-set.ts | 9 +++---- .../ordered-set/segment-iterator.ts | 4 ++-- src/mol-data/atom-set/base.ts | 6 ++--- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/mol-base/_spec/collections.spec.ts b/src/mol-base/_spec/collections.spec.ts index 6ed01e4bb..71330f576 100644 --- a/src/mol-base/_spec/collections.spec.ts +++ b/src/mol-base/_spec/collections.spec.ts @@ -208,18 +208,18 @@ describe('ordered set', () => { }); it('interval range', () => { - expect(OrderedSet.getIntervalRange(empty, 9, 11)).toEqual({ start: 0, end: 0 }); - expect(OrderedSet.getIntervalRange(empty, -9, -6)).toEqual({ start: 0, end: 0 }); - expect(OrderedSet.getIntervalRange(singleton10, 9, 11)).toEqual({ start: 0, end: 1 }); - expect(OrderedSet.getIntervalRange(range1_4, 2, 3)).toEqual({ start: 1, end: 3 }); - expect(OrderedSet.getIntervalRange(range1_4, -10, 2)).toEqual({ start: 0, end: 2 }); - expect(OrderedSet.getIntervalRange(range1_4, -10, 20)).toEqual({ start: 0, end: 4 }); - expect(OrderedSet.getIntervalRange(range1_4, 3, 20)).toEqual({ start: 2, end: 4 }); - expect(OrderedSet.getIntervalRange(arr136, 0, 1)).toEqual({ start: 0, end: 1 }); - expect(OrderedSet.getIntervalRange(arr136, 0, 3)).toEqual({ start: 0, end: 2 }); - expect(OrderedSet.getIntervalRange(arr136, 0, 4)).toEqual({ start: 0, end: 2 }); - expect(OrderedSet.getIntervalRange(arr136, 2, 4)).toEqual({ start: 1, end: 2 }); - expect(OrderedSet.getIntervalRange(arr136, 2, 7)).toEqual({ start: 1, end: 3 }); + expect(OrderedSet.findIntervalRange(empty, 9, 11)).toEqual({ start: 0, end: 0 }); + expect(OrderedSet.findIntervalRange(empty, -9, -6)).toEqual({ start: 0, end: 0 }); + expect(OrderedSet.findIntervalRange(singleton10, 9, 11)).toEqual({ start: 0, end: 1 }); + expect(OrderedSet.findIntervalRange(range1_4, 2, 3)).toEqual({ start: 1, end: 3 }); + expect(OrderedSet.findIntervalRange(range1_4, -10, 2)).toEqual({ start: 0, end: 2 }); + expect(OrderedSet.findIntervalRange(range1_4, -10, 20)).toEqual({ start: 0, end: 4 }); + expect(OrderedSet.findIntervalRange(range1_4, 3, 20)).toEqual({ start: 2, end: 4 }); + expect(OrderedSet.findIntervalRange(arr136, 0, 1)).toEqual({ start: 0, end: 1 }); + expect(OrderedSet.findIntervalRange(arr136, 0, 3)).toEqual({ start: 0, end: 2 }); + expect(OrderedSet.findIntervalRange(arr136, 0, 4)).toEqual({ start: 0, end: 2 }); + expect(OrderedSet.findIntervalRange(arr136, 2, 4)).toEqual({ start: 1, end: 2 }); + expect(OrderedSet.findIntervalRange(arr136, 2, 7)).toEqual({ start: 1, end: 3 }); }) testEq('union ES', OrderedSet.union(empty, singleton10), [10]); diff --git a/src/mol-base/collections/ordered-set.ts b/src/mol-base/collections/ordered-set.ts index 99325d25d..c1a697a91 100644 --- a/src/mol-base/collections/ordered-set.ts +++ b/src/mol-base/collections/ordered-set.ts @@ -8,6 +8,7 @@ import * as Base from './ordered-set/base' import SegmentIterator from './ordered-set/segment-iterator' namespace OrderedSet { + /** Range of indices to be iterated as start <= i < end. */ export interface IndexRange { start: number, end: number } export function IndexRange(start?: number, end?: number): IndexRange { return { start: start || 0, end: end || 0 }; } @@ -34,11 +35,11 @@ namespace OrderedSet { export const intersect: (a: OrderedSet, b: OrderedSet) => OrderedSet = Base.intersect as any; export const subtract: (a: OrderedSet, b: OrderedSet) => OrderedSet = Base.subtract as any; - export const getPredIndex: (set: OrderedSet, x: number) => number = Base.getPredIndex as any; - export const getPredIndexInRange: (set: OrderedSet, x: number, range: IndexRange) => number = Base.getPredIndexInRange as any; - export const getIntervalRange: (set: OrderedSet, min: number, max: number) => IndexRange = Base.getIntervalRange as any; + export const findPredecessorIndex: (set: OrderedSet, x: number) => number = Base.getPredIndex as any; + export const findPredecessorIndexInRange: (set: OrderedSet, x: number, range: IndexRange) => number = Base.getPredIndexInRange as any; + export const findIntervalRange: (set: OrderedSet, min: number, max: number) => IndexRange = Base.getIntervalRange as any; - export const segments = SegmentIterator + export const segments = SegmentIterator; } interface OrderedSet { '@type': 'int-ordered-set' } diff --git a/src/mol-base/collections/ordered-set/segment-iterator.ts b/src/mol-base/collections/ordered-set/segment-iterator.ts index 06642dba7..f5c7a712a 100644 --- a/src/mol-base/collections/ordered-set/segment-iterator.ts +++ b/src/mol-base/collections/ordered-set/segment-iterator.ts @@ -36,12 +36,12 @@ class SegmentIterator implements Iterator<{ segment: number } & OrderedSet.Index private getSegmentIndex(value: number) { if (value >= this.last) return -1; - return OrderedSet.getPredIndex(this.segments, value - 1); + return OrderedSet.findPredecessorIndex(this.segments, value - 1); } private updateValue() { const segmentEnd = OrderedSet.getAt(this.segments, this.segmentRange.start + 1); - const setEnd = OrderedSet.getPredIndexInRange(this.set, segmentEnd, this.setRange); + const setEnd = OrderedSet.findPredecessorIndexInRange(this.set, segmentEnd, this.setRange); this.value.start = this.setRange.start; this.value.end = setEnd; this.setRange.start = setEnd; diff --git a/src/mol-data/atom-set/base.ts b/src/mol-data/atom-set/base.ts index 2be02c26e..2147fc755 100644 --- a/src/mol-data/atom-set/base.ts +++ b/src/mol-data/atom-set/base.ts @@ -353,7 +353,7 @@ function areIntersectingEE(a: AtomSetElements, b: AtomSetElements) { if (a === b) return true; const keysA = a.keys, keysB = b.keys; if (!OrderedSet.areIntersecting(a.keys, b.keys)) return false; - const { start, end } = OrderedSet.getIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); + const { start, end } = OrderedSet.findIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); for (let i = start; i < end; i++) { const k = OrderedSet.getAt(keysA, i); if (OrderedSet.has(keysB, k) && OrderedSet.areIntersecting(a[k], b[k])) return true; @@ -372,7 +372,7 @@ function intersectEE(a: AtomSetElements, b: AtomSetElements) { const keysA = a.keys, keysB = b.keys; if (!OrderedSet.areIntersecting(a.keys, b.keys)) return Empty; - const { start, end } = OrderedSet.getIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); + const { start, end } = OrderedSet.findIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); const keys = [], ret = Object.create(null); for (let i = start; i < end; i++) { @@ -412,7 +412,7 @@ function subtractEE(a: AtomSetElements, b: AtomSetElements) { const keysA = a.keys, keysB = b.keys; if (!OrderedSet.areIntersecting(a.keys, b.keys)) return Empty; - const { start, end } = OrderedSet.getIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); + const { start, end } = OrderedSet.findIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); const keys = [], ret = Object.create(null); for (let i = 0; i < start; i++) { -- GitLab