/** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal */ import Interval from './interval' import OrderedSet from './ordered-set' import * as Impl from './impl/segmentation' namespace Segmentation { export interface Segment { index: I, start: number, end: number } export const create: (segs: ArrayLike) => Segmentation = Impl.create as any; export const ofOffsets: (offsets: ArrayLike, bounds: Interval) => Segmentation = Impl.ofOffsets as any; export const count: (segs: Segmentation) => number = Impl.count as any; export const getSegment: (segs: Segmentation, value: T) => number = Impl.getSegment as any; export const projectValue: (segs: Segmentation, set: OrderedSet, value: T) => Interval = Impl.projectValue as any; /** Segment iterator that mutates a single segment object to mark all the segments. */ export const transientSegments: (segs: Segmentation, set: OrderedSet, segment?: Segment) => Impl.SegmentIterator = Impl.segments as any; export type SegmentIterator = Impl.SegmentIterator } interface Segmentation { '@type': 'segmentation', /** All segments are defined by offsets [offsets[i], offsets[i + 1]) for i \in [0, count - 1] */ readonly offsets: ArrayLike, /** Segment index of the i-th element */ readonly index: ArrayLike, readonly count: number } export default Segmentation