h$'&6      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI>Closed intervals of totally ordered types, e.g. time intervals(c) Lackmann PhymetricGPL-3olaf.klinke@phymetric.de experimental Safe-Inferred>?%1closed-intervalsSearch tree of intervals.closed-intervals/class of Intervals whose bounds can be adjustedclosed-intervals!Time types supporting differencesclosed-intervalsclass of search structures for interval intersection queries, returning a J of intervals.closed-intervals%all intervalls touching the first one closed-intervals1all intervals properly intersecting the first one closed-intervals&does any interval touch the first one? closed-intervals3does any interval properly intersect the first one? closed-intervals overlapTime i i == intervalDuration igenInterval /\* \i j -> not (i `properlyIntersects` j) ==> overlapTime i j == 0genInterval /\* \i j -> overlapTime i j == (sum $ fmap intervalDuration $ maybeIntersection i j)closed-intervals0Prevailing annotation in the first time intervalgenInterval /\ \i c -> prevailing i (Seq.singleton (c,i)) == Just (c::Char)genInterval /\ \i -> genLabeledSeq /\ \js -> isJust (prevailing i js) == any (intersects i . snd) jsgenInterval /\ \i -> genLabeledSeq /\* \js ks -> all (flip elem $ catMaybes [prevailing i js, prevailing i ks]) $ prevailing i (js<>ks)closed-intervals isJust (maybeUnion i j) ==> fromJust (maybeUnion i j) `contains` i && fromJust (maybeUnion i j) `contains` jgenInterval /\* \i j -> i `intersects` j ==> (maybeUnion i j >>= maybeIntersection i) == Just iclosed-intervalsthe intersection of two intervals is either empty or an interval.genInterval /\* \i j -> i `intersects` j ==> i `contains` fromJust (maybeIntersection i j)closed-intervals convex hull\xs -> isJust (hull xs) ==> all (\x -> fromJust (hull xs) `contains` x) (xs :: [(Int,Int)])closed-intervalsSet difference. The resulting list has zero, one or two elements.without' (1,5) (4,5)[(1,4)]without' (1,5) (2,3) [(1,2),(3,5)]without' (1,5) (1,5)[]without' (1,5) (0,1)[(1,5)]3genInterval /\* \i j -> length (i `without` j) <= 2(genInterval /\ \i -> i `without` i == []8genInterval /\* \i j -> all (contains i) (i `without` j)genInterval /\* \i j -> not $ any (properlyIntersects j) (i `without` j)closed-intervals is not an equivalence relation, because it is not transitive. Hence groupBy  does not do what one might expect. This function does the expected and groups overlapping intervals into contiguous blocks.genSortedIntervals /\ all (\xs -> and $ List.zipWith intersects xs (tail xs)) . contiguousclosed-intervals)Connected components of a list sorted by # , akin to groupBy #. The precondition is not checked.genSortedIntervals /\ \xs -> all (\i -> any (flip contains i) (components xs)) xsclosed-intervalssame as . Is there a way to unify both?genSortedIntervals /\ \xs -> componentsSeq (Seq.fromList xs) == Seq.fromList (components xs)closed-intervals&compute the components of the part of i covered by the intervals.genInterval /\ \i -> genIntervalSeq /\ \js -> all (contains i) (covered i js)genInterval /\ \i -> genIntervalSeq /\ \js -> covered i (covered i js) == covered i jsclosed-intervalsK if the first interval is completely covered by the given intervals;genInterval /\* \i j -> j `contains` i == i `coveredBy` [j]genInterval /\ \i -> genSortedIntervals /\ \js -> i `coveredBy` js ==> any (flip contains i) (components js)closed-intervalspercentage of coverage of the first interval by the second sequence of intervalsgenNonEmptyInterval /\ \i -> genIntervalSeq /\ \js -> i `coveredBy` js == (fractionCovered i js >= (1::Rational))genNonEmptyInterval /\ \i -> genNonEmptyIntervalSeq /\ \js -> any (properlyIntersects i) js == (fractionCovered i js > (0::Rational))closed-intervalsOverlap ordering. Returns L or M! if the intervals are disjoint, N if the intervals overlap. Note that this violates the following property:  x y == N &&  y z == N =>  x z == N i.e.,  is not transitive.genInterval /\* \i j -> i `intersects` j == (overlap i j == EQ)closed-intervalsintersection query.2((1,2)::(Int,Int)) `intersects` ((2,3)::(Int,Int))TruegenInterval /\* \i j -> (lb i <= ub i && lb j <= ub j && i `intersects` j) == (max (lb i) (lb j) <= min (ub i) (ub j))closed-intervalsproper intersection.genInterval /\* \i j -> ((i `intersects` j) && not (i `properlyIntersects` j)) == (ub i == lb j || ub j == lb i) closed-intervalssubset containment#genInterval /\ \i -> i `contains` igenInterval /\* \i j -> (i `contains` j && j `contains` i) == (i==j)genInterval /\* \i j -> i `contains` j == (maybeUnion i j == Just i)!closed-intervalsproper subset containment"closed-intervalsconstruct a sorted sequence of intervals from a sorted sequence of bounds. Fails if the input sequence is not sorted.genSortedList /\ \xs -> (components $ toList $ fromEndPoints xs) == if length xs < 2 then [] else [(head xs, last xs)]#closed-intervalslexicographical sort by  , then inverse . In the resulting list, the intervals intersecting a given interval form a contiguous sublist.genInterval /\ \i -> genSortedIntervalSeq /\ \js -> toList (getIntersects i js) `List.isSubsequenceOf` toList js$closed-intervals/extract all intervals intersecting a given one.%closed-intervals8extract all intervals properly intersecting a given one.&closed-intervalsconvex hull of a sorted sequence of intervals. the lower bound is guaranteed to be in the leftmost interval, but we have no guarantee of the upper bound.=genSortedIntervalSeq /\ \xs -> hullSeq xs == hull (toList xs)'closed-intervals the empty (closed-intervals,smallest interval covering the entire tree. O if the tree is empty.)closed-intervals:invariant to be maintained for proper intersection queriesinvariant . itree 4 . fmap (\(x,y) -> (x, x + QC.getNonNegative y :: Integer))*closed-intervals.Intersection query. O(binsize+log(n/binsize)).genInterval /\ \i -> genIntervalSeq /\ \t -> on (==) sortByLeft (getIntersectsIT i $ itree 2 t) (i `intersecting` t)+closed-intervals.Intersection query. O(binsize+log(n/binsize)).genInterval /\ \i -> genIntervalSeq /\ \t -> on (==) sortByLeft (getProperIntersectsIT i $ itree 2 t) (i `intersectingProperly` t),closed-intervalsWhen the actual result of *9 is not important, only whether there are intersections.-closed-intervalsWhen the actual result of *9 is not important, only whether there are intersections..closed-intervals2retrieve the left-most interval from the tree, or O if it is empty./closed-intervals2transform the interval tree into the tree of hulls0closed-intervals!generalises Control.Monad.filterM2closed-intervalsSplit a Sequence in half, needed for the IntersectionQuery instances. prop> genIntervalSeq / is -> joinSeq (splitSeq is) == is3closed-intervalsinsert the interval at the deepest possible location into the tree. Does not change the overall structure, in particular no re-balancing is performed.4closed-intervalsConstruct an interval tree with bins of maximal given size. The function first sorts the intervals, then splits into chunks of given size. The leftmost endpoints of the chunks define boundary points. Next, all intervals properly overlapping a boundary are removed from the chunks and kept separately. The chunks are arranged as the leaves of a binary search tree. Then the intervals overlapping boundaries are placed at internal nodes of the tree. Hence if all intervals are mutually non-overlapping properly, the resulting tree is a pure binary search tree with bins of given size as leaves.5closed-intervalsO(log n)- bounds of an ordered sequence of intervals. O , if empty.genDisjointIntervalSeq /\ \xs -> hullSeqNonOverlap xs == hullSeq xs6closed-intervalsQuery an ordered P4uence of non-overlapping intervals for a predicate p that has the property j   k && p i k ==> p i j 1and return all elements satisfying the predicate.genInterval /\ \i -> genDisjointIntervalSeq /\ \js -> findSeq intersects i js == intersecting i js7closed-intervalsQuery an ordered P4uence of non-overlapping intervals for a predicate p that has the property j   k && p i k ==> p i j ;closed-intervals preserves the TimeZoneclosed-intervalsadjust lower and upper boundclosed-intervals*change both bounds using the same function closed-intervals lower boundclosed-intervals upper boundclosed-intervalsend points (inclusive)8  !"#$%&'()*+,-./012345678   !&#"4'3($*+,-.675)/%012 Safe-Inferred&)QRSTUVWX      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRPQSPQTPQUMVWXYZ[\]^_`ab/closed-intervals-0.1.0.1-1TVr3ky0vIMCt6ChAyndow Data.IntervalPaths_closed_intervalsITreeAdjust adjustBoundsshiftTimeDifferencediffTimeaddTimeIntersectionQuery getIntersectsgetProperIntersectssomeIntersectssomeProperlyIntersectsIntervallbub endPointsintervalDuration overlapTime prevailing maybeUnionmaybeIntersectionhullwithout contiguous components componentsSeqcovered coveredByfractionCoveredoverlap intersectsproperlyIntersectscontainsproperlyContains fromEndPoints sortByLeft intersectingintersectingProperlyhullSeq emptyITree hullOfTree invariantgetIntersectsITgetProperIntersectsITsomeIntersectsITsomeProperlyIntersectsITleftmostIntervaltoTreefilterMjoinSeqsplitSeqinsertitreehullSeqNonOverlapfindSeq existsSeq$fIntervaleIdentity$fIntervale(,)$fIntersectionQuerySeqeSeq$fTimeDifferenceZonedTime$fTimeDifferenceLocalTime$fTimeDifferenceUTCTime $fAdjuste(,)$fFoldableITree$fFunctorITree$fIntersectionQueryITreeeSeq $fShowBlock $fMonoidBlock$fSemigroupBlock$fFoldableBlock$fFunctorBlock $fOrdBlock $fEqBlock$fShowSplitSeqbase Data.FoldableFoldableghc-prim GHC.TypesTrueLTGTEQ GHC.MaybeNothingcontainers-0.6.2.1Data.Sequence.InternalSeqversion getBinDir getLibDir getDynLibDir getDataDir getLibexecDir getSysconfDirgetDataFileName