Skip to content
Snippets Groups Projects
Commit b92fa107 authored by Alexander Rose's avatar Alexander Rose
Browse files

docs

parent d09800fe
Branches
Tags
No related merge requests found
......@@ -8,7 +8,7 @@ import Tuple from '../tuple'
export const Empty = Tuple.Zero;
export function ofRange(min: number, max: number) { return max < min ? Tuple.create(min, min) : Tuple.create(min, max + 1); }
export function ofBounds(min: number, max: number) { return max <= min ? Tuple.create(min, min) : Tuple.create(min, max); }
export function ofBounds(start: number, end: number) { return end <= start ? Tuple.create(start, start) : Tuple.create(start, end); }
export const is = Tuple.is;
export const start = Tuple.fst;
......
......@@ -10,7 +10,14 @@ import Interval from '../interval'
import SortedArray from '../sorted-array'
import Segs from '../segmentation'
type Segmentation = { segments: SortedArray, segmentMap: Int32Array, count: number }
interface Segmentation {
/** Segments stored as a sorted array */
segments: SortedArray,
/** Mapping of values to segments */
segmentMap: Int32Array,
/** Number of segments */
count: number
}
export function create(values: ArrayLike<number>): Segmentation {
const segments = SortedArray.ofSortedArray(values);
......
......@@ -10,34 +10,47 @@ namespace Interval {
export const Empty: Interval = Impl.Empty as any;
export const ofSingleton: (value: number) => Interval = (v) => Impl.ofRange(v, v) as any;
/** Create interval [min, max] */
/** Create interval from range [min, max] */
export const ofRange: (min: number, max: number) => Interval = Impl.ofRange as any;
/** Create interval [min, max) */
/** Create interval from bounds [start, end), i.e. [start, end - 1] */
export const ofBounds: (start: number, end: number) => Interval = Impl.ofBounds as any;
export const is: (v: any) => v is Interval = Impl.is as any;
/** Test if a value is within the bounds of the interval */
export const has: (interval: Interval, x: number) => boolean = Impl.has as any;
export const indexOf: (interval: Interval, x: number) => number = Impl.indexOf as any;
export const getAt: (interval: Interval, i: number) => number = Impl.getAt as any;
/** Start value of the interval, same as min value */
export const start: (interval: Interval) => number = Impl.start as any;
/** End value of the interval, same as max + 1 */
export const end: (interval: Interval) => number = Impl.end as any;
/** Min value of the interval, same as start value */
export const min: (interval: Interval) => number = Impl.min as any;
/** Max value of the interval, same as end - 1 */
export const max: (interval: Interval) => number = Impl.max as any;
/** Number of values in the interval */
export const size: (interval: Interval) => number = Impl.size as any;
/** Hash code describing the interval */
export const hashCode: (interval: Interval) => number = Impl.hashCode as any;
/** Test if two intervals are identical */
export const areEqual: (a: Interval, b: Interval) => boolean = Impl.areEqual as any;
/** Test if two intervals are intersecting, i.e. their bounds overlap */
export const areIntersecting: (a: Interval, b: Interval) => boolean = Impl.areIntersecting as any;
/** Test if interval b is fully included in interval a */
export const isSubInterval: (a: Interval, b: Interval) => boolean = Impl.isSubInterval as any;
export const findPredecessorIndex: (interval: Interval, x: number) => number = Impl.findPredecessorIndex as any;
export const findPredecessorIndexInInterval: (interval: Interval, x: number, bounds: Interval) => number = Impl.findPredecessorIndexInInterval as any;
export const findRange: (interval: Interval, min: number, max: number) => Interval = Impl.findRange as any;
/** Get a new interval that is the intersection of the two intervals */
export const intersect: (a: Interval, b: Interval) => Interval = Impl.intersect as any;
}
/** Interval describing a range [min, max] of values */
interface Interval { '@type': 'int-interval' }
export default Interval
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment