Range consolidation: Difference between revisions

m
Formatting.
m (Formatting.)
Line 1,187:
else:
a[0] < b[0]
 
 
proc consolidate[T](rangeList: varargs[Range[T]]): seq[Range[T]] =
## Consolidate a list of ranges of type T.
 
# Build a sorted list of normalized ranges.
var list: seq[Range[T]]
for item in rangeList:
list.add if item[0] <= item[1]: item else: [item[1], item[0]]
# Sort the list.
list.sort()
 
# Build the consolidated list starting from "smallest" range.
result.add list[0]
Line 1,206 ⟶ 1,207:
else:
result.add rangeMax
 
 
proc `$`[T](r: Range[T]): string {.inline.} =
Anonymous user