/** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal */ 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: (value: T) => OrderedSet = Base.ofSingleton as any; export const ofRange: (min: T, max: T) => OrderedSet = Base.ofRange as any; export const ofBounds: (min: T, max: T) => OrderedSet = Base.ofBounds as any; /** It is the responsibility of the caller to ensure the array is sorted and contains unique values. */ export const ofSortedArray: (xs: ArrayLike) => OrderedSet = Base.ofSortedArray as any; export const has: (set: OrderedSet, x: T) => boolean = Base.has as any; export const indexOf: (set: OrderedSet, x: T) => number = Base.indexOf as any; export const getAt: (set: OrderedSet, i: number) => T = Base.getAt as any; export const min: (set: OrderedSet) => T = Base.min as any; export const max: (set: OrderedSet) => T = Base.max as any; export const start: (set: OrderedSet) => T = Base.start as any; export const end: (set: OrderedSet) => T = Base.end as any; export const size: (set: OrderedSet) => number = Base.size as any; export const hashCode: (set: OrderedSet) => number = Base.hashCode as any; export const areEqual: (a: OrderedSet, b: OrderedSet) => boolean = Base.areEqual as any; export const areIntersecting: (a: OrderedSet, b: OrderedSet) => boolean = Base.areIntersecting as any; /** Check if the 2nd argument is a subset of the 1st */ export const isSubset: (a: OrderedSet, b: OrderedSet) => boolean = Base.isSubset as any; export const union: (a: OrderedSet, b: OrderedSet) => OrderedSet = Base.union as any; 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 findPredecessorIndex: (set: OrderedSet, x: number) => number = Base.findPredecessorIndex as any; export const findPredecessorIndexInInterval: (set: OrderedSet, x: T, range: Interval) => number = Base.findPredecessorIndexInInterval as any; export const findRange: (set: OrderedSet, min: T, max: T) => Interval = Base.findRange as any; export const intersectionSize: (a: OrderedSet, b: OrderedSet) => number = Base.intersectionSize as any; export function forEach(set: OrderedSet, f: (v: T, i: number, ctx: Ctx) => void, ctx?: Ctx): Ctx { return Base.forEach(set as any, f as any, ctx); } export function isInterval(set: OrderedSet): set is Interval { return Interval.is(set); } export function isSortedArray(set: OrderedSet): set is SortedArray { return !Interval.is(set); } export function toArray(set: OrderedSet): T[] { const array: T[] = [] OrderedSet.forEach(set, v => array.push(v)) return array } } /** Represents bla */ type OrderedSet = SortedArray | Interval export default OrderedSet