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
i
be the intersection betweenl.interval
andr.interval
.if
i
is not empty, leto
be the output ofop(l.value, r.value, i)
.if
o
is notnull
, the result will contain a segment with valueo
on the intervali
. Additionally, for each pair of segments
in either list and gap in the other list:let
i
be the intersection betweens.interval
and the gap.if
i
is not empty, leto
be the output of eitherop(s.value, null, i)
orop(null, s.value, i)
, depending on which list the segment came from.if
o
is notnull
, the result will contain a segment with valueo
on 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.