@@ -59,6 +59,9 @@ def read(self) -> None:
5959 self .config = {}
6060 current_pos_line_found = False
6161
62+ # Reset transitions to initial state before reading
63+ self .transitions = [(0 , NO_SORT , STATUS_UNTRIED ), (self .size , NO_SORT , STATUS_UNTRIED )]
64+
6265 with self .map_path .open ("r" ) as file :
6366 for line in file :
6467 line = line .strip ()
@@ -97,6 +100,10 @@ def read(self) -> None:
97100 # Process normal data lines
98101 self ._process_data_line (line )
99102
103+ # Ensure we always have the final boundary transition
104+ if not self .transitions or self .transitions [- 1 ][0 ] != self .size :
105+ self .transitions .append ((self .size , NO_SORT , STATUS_UNTRIED ))
106+
100107 def _process_data_line (self , line : str ) -> None :
101108 """Process a data line with pos/size/status format."""
102109 parts = line .split ()
@@ -162,11 +169,15 @@ def set_status(self, start: int, end: int, status: str) -> None:
162169 before_idx = max (start_idx - 1 , 0 )
163170 after_idx = min (end_idx , len (self .transitions ) - 1 )
164171
165- # Get the status that should follow our range
166- before_status = self .transitions [before_idx ][2 ]
167- before_pos = self .transitions [before_idx ][0 ]
168- after_status = self .transitions [after_idx ][2 ]
169- after_pos = self .transitions [after_idx ][0 ]
172+ # Get the 5 variables we need
173+ before_status = self .transitions [before_idx ][2 ] # before_start.status
174+ before_pos = self .transitions [before_idx ][0 ] # before_start.pos
175+ after_status = self .transitions [after_idx ][2 ] # after.status
176+ after_pos = self .transitions [after_idx ][0 ] # after.pos
177+
178+ # Find before_end: what status exists at end+1 position before our change
179+ before_end_idx = max (0 , end_idx - 1 )
180+ before_end_status = self .transitions [before_end_idx ][2 ]
170181
171182 splice = []
172183 if before_pos == start :
@@ -178,8 +189,8 @@ def set_status(self, start: int, end: int, status: str) -> None:
178189 # if the status is different, we need to add a new entry
179190 splice .append (start_key )
180191
181- if after_status != status :
182- splice .append ((end + 1 , NO_SORT , after_status ))
192+ if before_end_status != status :
193+ splice .append ((end + 1 , NO_SORT , before_end_status ))
183194 if end + 1 < after_pos :
184195 splice .append ((after_pos , NO_SORT , after_status ))
185196
0 commit comments