Class ADT.Interval (< RangeType >)

class ADT.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

ADT.CritBit.RangeSet


Generic RangeType

__generic__ mixed RangeType = mixed

Description

Type of the endpoint values. Values must support < and >; numeric endpoints also support sizeof().


Variable a
Variable b

Boundary(< RangeType >) ADT.Interval.a
Boundary(< RangeType >) ADT.Interval.b

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

start, stop


Variable start

RangeType ADT.Interval.start

Description

Getting

See also

a, beginning()


Variable stop

RangeType ADT.Interval.stop

Description

Getting

See also

b, end()


Method create

ADT.Interval ADT.Interval(RangeType|Boundary(< RangeType >) a, RangeType|Boundary(< RangeType >) b)

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.