@@ -323,8 +323,20 @@ def union_interval_lists(left: list[Interval], right: list[Interval]) -> list[In
323
323
324
324
IntervalConstructor = Callable [[int , int , typing .List [AnyInterval ]], AnyInterval ]
325
325
326
+ def default_is_same_result (interval_constructor ):
327
+ def is_same_result (active_intervals1 , active_intervals2 ):
328
+ # When we have to decide whether to extend a result interval
329
+ # or start a new one, we compare the state for the existing
330
+ # result interval with the new state. The states are derived
331
+ # from the respective lists of active intervals by calling
332
+ # interval_constructor (with fake points in time) .
333
+ return (interval_constructor (0 , 0 , active_intervals1 )
334
+ == interval_constructor (0 , 0 , active_intervals2 ))
335
+ return is_same_result
336
+
326
337
def find_rectangles (all_intervals : list [list [AnyInterval ]],
327
- interval_constructor : IntervalConstructor ) \
338
+ interval_constructor : IntervalConstructor ,
339
+ is_same_result = None ) \
328
340
-> list [AnyInterval ]:
329
341
"""For multiple parallel "tracks" of intervals, identify temporal
330
342
intervals in which no change occurs on any "track". For each such
@@ -350,6 +362,9 @@ def find_rectangles(all_intervals: list[list[AnyInterval]],
350
362
that adjacent intervals (i.e. without gaps between them)
351
363
have different "payloads".
352
364
"""
365
+ if is_same_result is None :
366
+ is_same_result = default_is_same_result (interval_constructor )
367
+
353
368
# Convert all intervals into a single list of events sorted by
354
369
# time. Multiple events at the same point in time can be problem
355
370
# here: If an interval open event and an interval close event on
@@ -390,15 +405,6 @@ def add_segment(start, end, original_intervals):
390
405
result .append (interval )
391
406
previous_end = end
392
407
393
- def is_same_result (active_intervals1 , active_intervals2 ):
394
- # When we have to decide whether to extend a result interval
395
- # or start a new one, we compare the state for the existing
396
- # result interval with the new state. The states are derived
397
- # from the respective lists of active intervals by calling
398
- # interval_constructor (with fake points in time) .
399
- return (interval_constructor (0 ,0 ,active_intervals1 )
400
- == interval_constructor (0 ,0 ,active_intervals2 ))
401
-
402
408
active_intervals = [None ] * track_count
403
409
def process_events_for_point_in_time (index , point_time ):
404
410
high_time = point_time
0 commit comments