|
8 | 8 |
|
9 | 9 | import json
|
10 | 10 | from dataclasses import dataclass
|
11 |
| -from typing import Any, Dict, List |
| 11 | +from typing import Any, Dict, List, Union |
12 | 12 |
|
13 | 13 | # ============================================================================
|
14 | 14 | # Core Data Structures for AIG Path Analysis
|
@@ -290,14 +290,26 @@ def __len__(self) -> int:
|
290 | 290 | """Get the number of paths in the collection."""
|
291 | 291 | return self.length
|
292 | 292 |
|
293 |
| - def __getitem__(self, index: int) -> DataflowPath: |
| 293 | + def __getitem__( |
| 294 | + self, index: Union[slice, |
| 295 | + int]) -> Union[DataflowPath, List[DataflowPath]]: |
294 | 296 | """
|
295 | 297 | Get a specific path from the collection by index.
|
296 |
| - Supports negative indexing. Results are cached to avoid expensive |
297 |
| - JSON parsing on repeated access. |
| 298 | + Supports both integer and slice indexing. Integer indices can be negative. |
| 299 | + Results are cached to avoid expensive JSON parsing on repeated access. |
| 300 | +
|
298 | 301 | Args:
|
299 |
| - index: Index of the path to retrieve (0 = longest path) |
| 302 | + index: Integer index or slice object to access paths |
| 303 | +
|
| 304 | + Returns: |
| 305 | + DataflowPath or list of DataflowPaths for slice access |
| 306 | +
|
| 307 | + Raises: |
| 308 | + IndexError: If index is out of range |
300 | 309 | """
|
| 310 | + if isinstance(index, slice): |
| 311 | + return [self[i] for i in range(*index.indices(len(self)))] |
| 312 | + |
301 | 313 | # Handle negative indexing
|
302 | 314 | if index < 0:
|
303 | 315 | index += self.length
|
|
0 commit comments