sprig.intervals module

Utilities for working with intervals.

class sprig.intervals.SupportsLessThan(*args, **kwds)

Bases: typing_extensions.Protocol

sprig.intervals.auto_intersections(intervals: Mapping[HashableT, Tuple[SupportsLessThanT, SupportsLessThanT]])Dict[FrozenSet[HashableT], Tuple[SupportsLessThanT, SupportsLessThanT]]

All intervals formed by intersecting two of the given intervals

>>> auto_intersections({0:(0,3), 1:(5,6), 2:(2,4)})
{frozenset({0, 2}): (2, 3)}
sprig.intervals.intersecting_combinations(intervals: Mapping[HashableT, Tuple[SupportsLessThanT, SupportsLessThanT]], k: int)Dict[FrozenSet[HashableT], Tuple[SupportsLessThanT, SupportsLessThanT]]

All intervals formed by reducing k-combinations with intersection

In no particular order.

sprig.intervals.intersecting_products(factors: Sequence[Mapping[HashableT, Tuple[SupportsLessThanT, SupportsLessThanT]]])Mapping[Sequence[HashableT], Tuple[SupportsLessThanT, SupportsLessThanT]]

All intervals formed by reducing products with intersection.

In other words every interval that can be formed by intersecting exactly one interval from each of the factors.

>>> intersecting_products([{0: (1, 7)}, {1:(3, 9)}, {2: (0, 2), 3: (0,4)}])
{(0, 1, 3): (3, 4)}

Note that the time complexity worse if intervals within a factor may intersect. It is potentially much worse if a large portion of the intervals do intersect.

sprig.intervals.intersecting_subsets(intervals: Mapping[HashableT, Tuple[SupportsLessThanT, SupportsLessThanT]])Dict[FrozenSet[HashableT], Tuple[SupportsLessThanT, SupportsLessThanT]]

All intervals formed by reducing subsets with intersection

In no particular order.

sprig.intervals.without_degenerate(intervals: Mapping[HashableT, Tuple[SupportsLessThanT, SupportsLessThanT]])Dict[HashableT, Tuple[SupportsLessThanT, SupportsLessThanT]]

Return only proper intervals

>>> without_degenerate({0:(1,1), 1:(2,3)})
{1: (2, 3)}