Skip to content

Commit

Permalink
fix: improve index clarity in heapifyUp
Browse files Browse the repository at this point in the history
Co-authored-by: Mario Carneiro <di.gama@gmail.com>
  • Loading branch information
fgdorais and digama0 committed Jul 19, 2024
1 parent d931ef7 commit 0ab5b1a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Batteries/Data/BinaryHeap.lean
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def heapifyUp (lt : α → α → Bool) (a : Vector α sz) (i : Fin sz) :
Vector α sz :=
match i with
| ⟨0, _⟩ => a
| ⟨i+1, hi⟩ =>
if lt a[i/2] a[i+1] then
heapifyUp lt (a.swapN (i+1) (i/2)) ⟨i/2, by get_elem_tactic⟩
| ⟨i'+1, hi⟩ =>
let j := ⟨i'/2, by get_elem_tactic⟩
if lt a[j] a[i] then
heapifyUp lt (a.swap i j) j
else a

/-- `O(1)`. Build a new empty heap. -/
Expand Down

0 comments on commit 0ab5b1a

Please sign in to comment.