Range consolidation: Difference between revisions

m
Efficiency improvement
(Added C solution)
m (Efficiency improvement)
Line 191:
size_t consolidate_ranges(range_t* ranges, size_t count) {
normalize_ranges(ranges, count);
for (size_t iout_index = 0; i < count; ++i) {
for (size_t ni = 0,; ji =< icount; ) {
forsize_t (; ++j < count && ranges[j].low <= ranges[i].high; ++n) {
while (++j < count && ranges[kj].low <= ranges[ji];.high) {
if (ranges[i].high < ranges[j].high)
ranges[i].high = ranges[j].high;
}
ifranges[out_index++] (n= > 0) {ranges[i];
i count -= nj;
for (size_t k = i + 1; k < count; ++k, ++j)
ranges[k] = ranges[j];
}
}
return countout_index;
}
 
1,777

edits