What is the best approach to query a list of date intervals
for overlapping intervals, given granularity to the second (or even millisecond)?
From the exhaustive list of other questions regarding overlapping integer intervals, I was pointed to the Interval Tree. After reading it, I modified this implementation, which handles integer intervals, for dates.
His search implementation loops from the starting search interval to the ending search interval, recursively appending from the left node or right node as appropriate. This works great if your intervals are close integers (or if your date intervals have granularity down to the hour and are between a day).
I simply decided to loop over the starting search date (converted to seconds) to the ending search interval (converted to seconds via int(time - epoch
)), which of course results in a loop of 3600 for searching over a one hour interval. Converting to milliseconds, an hour loop would be 3,600,000!
When searching for overlapping date intervals with granularity down to the second, or millisecond, what is the appropriate algorithmic data structure to use? Is there a better way to implement the Interval Tree than looping over every second?