Skip to content

Commit

Permalink
Fix backwards iteration in cache hierarchy logic
Browse files Browse the repository at this point in the history
The recent cache refactoring had caused the hierarchy iteration to
not work correctly. In particular, backwards iteration did not
work over module boundaries like before.
  • Loading branch information
PasiSa authored and rkdarst committed Dec 20, 2023
1 parent 6ea0e44 commit c4e6b10
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions exercise/cache/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,17 @@ def _go_to_last(indices: List[int]):

if skip_first:
# Move the starting index to the previous element
if tree_indices[-1] == 0:
tree_indices = tree_indices[-1]
lastidx = len(tree_indices) - 1
while tree_indices[lastidx] == 0:
if lastidx < 1:
tree_indices = 0
break
if tree_indices[lastidx - 1] >= 0:
# if we are at the first chapter at the current level, move to previous item at
# next highest level (or move further up the tree, if not possible)
tree_indices.pop()
break
lastidx -= 1
else:
tree_indices[-1] -= 1
_go_to_last(tree_indices)
Expand Down

0 comments on commit c4e6b10

Please sign in to comment.