map2SegmentLists
Low level routine for performing a binary operation on a pair of segment lists.
Assumes both lists are properly coalesced - NOT CHECKED. Violating this assumption is UB.
The resulting segment list is defined as follows. (This is a definition of the result, not the algorithm to calculate it.) For each pair of segments l and r from the left and right lists (respectively):
let
ibe the intersection betweenl.intervalandr.interval.if
iis not empty, letobe the output ofop(l.value, r.value, i).if
ois notnull, the result will contain a segment with valueoon the intervali. Additionally, for each pair of segmentsin either list and gap in the other list:let
ibe the intersection betweens.intervaland the gap.if
iis not empty, letobe the output of eitherop(s.value, null, i)orop(null, s.value, i), depending on which list the segment came from.if
ois notnull, the result will contain a segment with valueoon the intervali.
This routine performs a single pass down each list, with a computational complexity proportional to the total number of segments in both lists.