Masker can be used to compute the intersection of two masks.
alias Interval = Tuple!(size_t, "begin", size_t, "end"); auto mask = masker!( "a.begin", "a.end", level => level >= 2 ? 1 : 0, )( [ Interval(1, 5), Interval(6, 7), Interval(9, 10), ], [Interval(0, 10)] ); alias I = mask.FrontType; assert(equal(mask.save, [I(0, 10, 0)])); auto intersection1 = mask.withAdditionalIntervals([Interval(4, 7)]); assert(equal( intersection1, [ I(0, 4, 0), I(4, 5, 1), I(5, 6, 0), I(6, 7, 1), I(7, 10, 0), ] ), investigateMask(mask, "mask does not match")); auto intersection2 = mask.withAdditionalIntervals([Interval(8, 10)]); assert(equal( intersection2, [ I(0, 9, 0), I(9, 10, 1), ] ), investigateMask(mask, "mask does not match"));
Add more intervals to masker without memory allocation for the original intervals.