fix another Vector.tabulate bug (else if statement starting from line 473)

This commit is contained in:
2024-07-01 06:52:32 +01:00
parent c9a221b5bd
commit 1be8a40e48

View File

@@ -413,6 +413,7 @@ struct
(* If we can join newString/lines with sub1 while (* If we can join newString/lines with sub1 while
* staying in limit. *) * staying in limit. *)
let let
(* VERIFIED TO WORK *)
val _ = print "line 416\n\n\n" val _ = print "line 416\n\n\n"
val _ = print val _ = print
("vector length: " ^ Int.toString (Vector.length newLines) ^ "\n") ("vector length: " ^ Int.toString (Vector.length newLines) ^ "\n")
@@ -442,12 +443,12 @@ struct
val newRightLines = val newRightLines =
if midpoint >= 0 then if midpoint >= 0 then
(* Implicit: a binSearch match was found. *) (* Implicit: a binSearch match was found. *)
Vector.tabulate Vector.tabulate
( (Vector.length leftLinesHd - midpoint) - 1 ( (Vector.length leftLinesHd - midpoint) - 1
, fn idx => , fn idx =>
Vector.sub (leftLinesHd, idx + midpoint + 1) Vector.sub (leftLinesHd, idx + midpoint + 1)
- String.size strSub1 - String.size strSub1
) )
else else
Vector.map (fn idx => idx - String.size strSub1) leftLinesHd Vector.map (fn idx => idx - String.size strSub1) leftLinesHd
in in
@@ -474,30 +475,41 @@ struct
(* If we can join newString/line with sub2 while staying (* If we can join newString/line with sub2 while staying
* in limit. *) * in limit. *)
let let
val _ = print "line 292\n" (* VERIFIED TO WORK *)
(* val _ = print "line 478\n"
val newLeftLines = VectorSlice.slice (leftLinesHd, 0, SOME midpoint) val newLeftLines =
val newLeftLines = VectorSlice.vector newLeftLines if midpoint >= 0 andalso Vector.length leftLinesHd > 0 then
let
val newRightLines = val newLeftLines = VectorSlice.slice
Vector.tabulate (leftLinesHd, 0, SOME (midpoint + 1))
( (Vector.length leftLinesHd - midpoint) in
+ Vector.length newLines VectorSlice.vector newLeftLines
, fn idx => end
if idx < Vector.length newLines then else
Vector.sub (newLines, idx) Vector.fromList []
else
(Vector.sub (leftLinesHd, idx - Vector.length newLines) val newRightLines =
- String.size strSub1) + String.size newString Vector.tabulate
) *) ( (Vector.length leftLinesHd - Vector.length newLeftLines)
+ Vector.length newLines
, fn idx =>
if idx < Vector.length newLines then
Vector.sub (newLines, idx)
else
Vector.sub
( leftLinesHd
, (idx - Vector.length newLines)
+ Vector.length newLeftLines
) - String.size strSub1 + String.size newString
)
in in
verifyReturn verifyReturn
{ idx = prevIdx + String.size strSub1 { idx = prevIdx + String.size strSub1
, line = (curLine - Vector.length leftLinesHd) + midpoint , line = (curLine - Vector.length leftLinesHd) + midpoint
, leftStrings = strSub1 :: leftStringsTl , leftStrings = strSub1 :: leftStringsTl
, leftLines = countLineBreaks strSub1 :: leftLinesTl , leftLines = newLeftLines :: leftLinesTl
, rightStrings = (newString ^ strSub2) :: rightStrings , rightStrings = (newString ^ strSub2) :: rightStrings
, rightLines = countLineBreaks (newString ^ strSub2) :: rightLines , rightLines = newRightLines :: rightLines
} }
end end
else else