isContiguous

Predicate that checks contiguity of the array of Range!T.

This function's result is equivalent to !hasGap && !hasOverlap. There is a special unittest which asserts this (see below). It has been implemented as a separate function because a more efficient implementation is possible.

It is assumed that the array is already sorted in lexicographical order: first check left boundaries of ranges if equal then right boundaries will be checked (that is current status quo of opCmp). All empty ranges are ignored.

bool
isContiguous
(
T
)
()

Parameters

ranges Range!(T)[]

a sorted array of Range!T to be checked

Return Value

Type: bool

true if collection is contiguous

Examples

Special unittest which checks that: isContiguous <=> !hasGap && !hasOverlap

Range!(uint)[] ranges;

// ranges is null
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));

// contiguous ranges
ranges ~= [Range!(uint)(1, 5), Range!(uint)(6, 12), Range!(uint)(13, 15)];
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));
ranges.length = 0;
assumeSafeAppend(ranges);

// overlap
ranges ~= [Range!(uint)(1, 5), Range!(uint)(6, 13), Range!(uint)(13, 15)];
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));
ranges.length = 0;
assumeSafeAppend(ranges);

// gap
ranges ~= [Range!(uint)(1, 4), Range!(uint)(6, 12), Range!(uint)(13, 15)];
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));
ranges.length = 0;
assumeSafeAppend(ranges);

// gap and overlap
ranges ~= [Range!(uint)(1, 4), Range!(uint)(6, 13), Range!(uint)(13, 15)];
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));
ranges.length = 0;
assumeSafeAppend(ranges);

// range.length == 0
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));

// only empty ranges
ranges ~= Range!(uint).init;
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));
ranges ~= Range!(uint).init;
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));
ranges ~= Range!(uint).init;
test!("==")(isContiguous(ranges), !hasGap(ranges) && !hasOverlap(ranges));

Meta