I'm working on a script that checks if time slices overlap or not.
I have a handler function that looks like this:
def intersection_checker(foo, bar):
if foo == bar:
return True
if foo[0] == bar[1] or foo[1] == bar[0]:
return True
if bar[0] < (foo[0] or foo[1]) < bar[1]:
return True
if foo[0] < (bar[0] or bar[1]) < foo[1]:
return True
return False
Object foo is a tuple of two datetime.time() objects:
foo = (datetime.strptime('06:30:00','%H:%M:%S').time(), datetime.strptime('08:15:00','%H:%M:%S').time())
Object bar is a set() of foo-like datetime.time() objects. That set can include 200+ k of that objects.
The line that calls the handler (intersection_checker) looks like this:
...
if len(bar) > 1 and True in set(map(intersection_checker, repeat(foo), bar)):
...
This code works. The problem is that it takes centuries to process such a large amount of data. I tried using a for loop to iterate trough function, but that didn't work as well as using the built-in map. Perhaps there is a way to transfer and process large amounts of data more efficiently? Or check intersections in a different way? And yes, it is enough to only find the first True value, it is not necessary to loop through the entire bar.