Skip to content

Commit

Permalink
fix: Timsort - account for arbitrary bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Senipah committed Nov 25, 2020
1 parent 9751d4b commit f8ee70c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/BetterArray.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3524,7 +3524,9 @@ Attribute TimSort.VB_Description = "Iterative Timsort"
Dim Start As Long
Dim Midpoint As Long
Dim Endpoint As Long
Dim LastIndex As Long

LastIndex = UBound(Source)
Size = MIN_RUN
Do While Size < SourceLength
' Determine the arrays that will
Expand All @@ -3534,8 +3536,8 @@ Attribute TimSort.VB_Description = "Iterative Timsort"
' Compute the `midpoint` (where the first array ends
' and the second starts) and the `endpoint` (where
' the second array ends)
Midpoint = Min(Start + Size - 1, SourceLength - 1)
Endpoint = Min(Start + Size * 2 - 1, SourceLength - 1)
Midpoint = Min(Start + Size - 1, LastIndex)
Endpoint = Min(Start + Size * 2 - 1, LastIndex)
' Merge the two subarrays.
' The `left` array should go from `start` to
' `midpoint + 1`, while the `right` array should
Expand Down

0 comments on commit f8ee70c

Please sign in to comment.