Open hvenev-insait opened 5 months ago
have you considered opening a PR?
Not yet. I am not sure what the best way to fix this is. Do we want to maintain the current behavior (in which case all we need to do is delete insertion_sort_shift_right
), or do we want to go back to the behavior before a3065a1a34fe1c0b85bdf3ff1f3d0bd470235e6b (probably call insertion_sort_shift_right
on v[i..]
instead of v[..i]
)?
Also, do we have any benchmarks for that code?
In
partial_insertion_sort
, an invariant is maintained thatv[..i]
is sorted. When a non-sorted pairv[i-1] > v[i]
is encountered, they are swapped and the last element ofv[..i]
is shifted to the left into its correct spot. Then for some reasoninsertion_sort_shift_right
is called onv[..i]
, attempting to shiftv[0]
to the right, which never does anything.Before commit a3065a1a34fe1c0b85bdf3ff1f3d0bd470235e6b, the shift was happening on
v[i..]
(instead ofv[..i]
), attempting to shiftv[i]
to the right, which makes more sense.