ui: more information

This commit is contained in:
Dobin
2024-04-14 21:37:54 +01:00
parent 4901c7b320
commit 70c4a95b1b
7 changed files with 95 additions and 25 deletions
+30 -1
View File
@@ -45,4 +45,33 @@ class RangeManager:
last_end = max(last_end, end)
if last_end < self.max and self.max - last_end >= hole_size:
holes.append((last_end + 1, self.max))
return holes
return holes
def find_largest_gap(self):
# First, sort intervals by the starting point
sorted_intervals = sorted(self.intervals, key=lambda x: x.begin)
# Initial largest gap is 0
largest_gap = 0
# Start by considering the gap from min to the first interval's start, if there are any intervals
if sorted_intervals:
largest_gap = sorted_intervals[0].begin - self.min
# Iterate over the intervals and find the gap between consecutive intervals
last_end = sorted_intervals[0].end if sorted_intervals else self.min
for interval in sorted_intervals[1:]:
# Calculate the gap between the current interval's start and the last interval's end
current_gap = interval.begin - last_end
if current_gap > largest_gap:
largest_gap = current_gap
last_end = max(last_end, interval.end) # Update last_end considering overlapping intervals
# Finally consider the gap from the last interval's end to max
if sorted_intervals:
final_gap = self.max - sorted_intervals[-1].end
if final_gap > largest_gap:
largest_gap = final_gap
return largest_gap