Class ADT.Interval (< RangeType >)
classADT.Interval (< RangeType >)- Description
An interval with independently open or closed endpoints.
Plain endpoint values create a closed interval. To exclude an endpoint, pass an Open boundary instead; Closed explicitly includes it. Endpoint values must support ordering comparisons.
- Example
ADT.Interval(<int>) i = ADT.Interval(<int>)(1, 4); i->contains(1); // 1 i->contains(5); // 0 sizeof(i); // 3: the distance between endpoints array endpoints = (array)i; // ({ 1, 4 })
// Boundary classes belong to an interval instance. ADT.Interval(<int>) j = i->clone(i->Open(1), i->Closed(4)); j->contains(1); // 0 j->contains(4); // 1
Intervals support intersection (
&), combination (|or+), and subtraction (-). The result must be representable as a single interval; see the individual operators for their restrictions. An empty result is represented by zero.- Bugs
Equal-coordinate boundary selection uses the same min() and max() rules for lower and upper endpoints. Consequently, contains() can include an open upper endpoint, and combining two intervals with equal upper endpoint values can choose an open upper boundary even when one interval includes that endpoint. Intersection and subtraction inherit these endpoint limitations.
- See also
- Generic
RangeType
__generic__mixedRangeType=mixed- Description
Type of the endpoint values. Values must support
<and>; numeric endpoints also support sizeof().
- Variable
a
Variable b
Boundary(<>) ADT.Interval.aRangeType
Boundary(<>) ADT.Interval.bRangeType- Description
The lower and upper boundaries, respectively. They retain both the endpoint value and whether that endpoint is included.
- Note
Direct assignment does not check that the interval remains nonempty.
- See also
- Method
create
ADT.Interval ADT.Interval(|RangeTypeBoundary(<>)RangeTypea,|RangeTypeBoundary(<>)RangeTypeb)- Description
Create an interval from its lower and upper endpoints.
- Parameter
a The lower value or boundary.
- Parameter
b The upper value or boundary.
Plain values are wrapped in Closed boundaries. The endpoints are not reordered. An error is thrown if the upper boundary does not overlap the lower one. Equal endpoint values are accepted only when both boundaries are closed.