some bug fixing. (Code is in a messed up/broken/deoptimised stated, but I will fix that once all bugs are address.)

This commit is contained in:
2024-06-30 15:14:21 +01:00
parent 9e451fea93
commit 06ca2a27a4
3 changed files with 441 additions and 246 deletions

View File

@@ -19,7 +19,7 @@ struct
if prevChar = #"\r" then if prevChar = #"\r" then
helpCountLineBreaks (pos - 2, (pos - 1) :: acc, str) helpCountLineBreaks (pos - 2, (pos - 1) :: acc, str)
else else
helpCountLineBreaks (pos - 2, pos :: acc, str) helpCountLineBreaks (pos - 1, pos :: acc, str)
end end
else if chr = #"\r" then else if chr = #"\r" then
helpCountLineBreaks (pos - 1, pos :: acc, str) helpCountLineBreaks (pos - 1, pos :: acc, str)
@@ -41,6 +41,56 @@ struct
, rightLines: int vector list , rightLines: int vector list
} }
fun lineBreaksToString vec =
(Vector.foldr (fn (el, acc) => Int.toString el ^ ", " ^ acc) "" vec) ^ "\n"
fun checkLineBreaks (v1, v2) =
if v1 = v2 then
()
else
let
val _ = print ("broken: " ^ (lineBreaksToString v1))
val _ = print ("fixed: " ^ (lineBreaksToString v2))
in
()
end
fun checkLineBreaksWithString (dir, str, lines) =
if countLineBreaks str <> lines then
let
val _ = print (dir ^ "\n")
val _ = print ("broken: " ^ lineBreaksToString lines)
val _ = print ("fixed: " ^ (lineBreaksToString (countLineBreaks str)))
val _ = raise Size
in
()
end
else
()
fun verifyReturn (buffer: t) =
let
val _ =
case (#leftStrings buffer, #leftLines buffer) of
(sHd :: _, lHd :: _) =>
let val _ = checkLineBreaksWithString ("left", sHd, lHd)
in ()
end
| (_, _) => ()
val _ =
case (#rightStrings buffer, #rightLines buffer) of
(sHd :: _, lHd :: _) =>
let val _ = checkLineBreaksWithString ("right", sHd, lHd)
in ()
end
| (_, _) => ()
in
buffer
end
local local
fun goToStart (leftStrings, leftLines, accStrings, accLines) = fun goToStart (leftStrings, leftLines, accStrings, accLines) =
case (leftStrings, leftLines) of case (leftStrings, leftLines) of
@@ -57,8 +107,11 @@ struct
if checkLines = lHd then if checkLines = lHd then
verifyLineList (strTl, lTl) verifyLineList (strTl, lTl)
else else
let val _ = print "line metadata is incorrect\n" let
in raise Empty val _ = print "line metadata is incorrect\n"
val _ = checkLineBreaks (lHd, checkLines)
in
raise Empty
end end
end end
| (_, _) => print "verified lines; no problems\n" | (_, _) => print "verified lines; no problems\n"
@@ -108,7 +161,18 @@ struct
andalso Vector.length v1 + Vector.length v2 <= vecLimit andalso Vector.length v1 + Vector.length v2 <= vecLimit
local local
fun helpBinSearch (findNum, lines, low, high) = fun reverseLinearSearch (findNum, idx, lines) =
if idx < 0 then
idx
else
let
val curVal = Vector.sub (lines, idx)
in
if curVal < findNum then idx
else reverseLinearSearch (findNum, idx, lines)
end
fun helpBinSearch (findNum, lines, low, high, prevLow, prevHigh) =
let let
val mid = low + ((high - low) div 2) val mid = low + ((high - low) div 2)
in in
@@ -117,19 +181,36 @@ struct
val midVal = Vector.sub (lines, mid) val midVal = Vector.sub (lines, mid)
in in
if midVal = findNum then if midVal = findNum then
mid (print "return 173\n"; mid)
else if midVal < findNum then else if midVal < findNum then
helpBinSearch (findNum, lines, mid + 1, high) helpBinSearch (findNum, lines, mid + 1, high, low, high)
else else
helpBinSearch (findNum, lines, low, mid - 1) helpBinSearch (findNum, lines, low, mid - 1, low, high)
end end
else else
Int.max (0, mid) let
val prevLowVal = Vector.sub (lines, prevLow)
val prevHighVal = Vector.sub (lines, prevHigh)
val _ = print ("prevLowVal: " ^ Int.toString prevLowVal ^ "\n")
val _ = print ("prevHighVal: " ^ Int.toString prevHighVal ^ "\n")
val _ = print ("findNum: " ^ Int.toString findNum ^ "\n")
in
(print "return 180\n"; reverseLinearSearch (findNum, mid, lines))
end
end end
in in
fun binSearch (findNum, lines) = fun binSearch (findNum, lines) =
if Vector.length lines = 0 then 0 if Vector.length lines = 0 then
else helpBinSearch (findNum, lines, 0, Vector.length lines - 1) 0
else
helpBinSearch
( findNum
, lines
, 0
, Vector.length lines - 1
, 0
, Vector.length lines - 1
)
end end
fun insWhenIdxAndCurIdxAreEqual fun insWhenIdxAndCurIdxAreEqual
@@ -141,12 +222,13 @@ struct
, leftLines , leftLines
, rightStrings , rightStrings
, rightLines , rightLines
) = ) : t =
case (leftStrings, leftLines) of case (leftStrings, leftLines) of
(strHd :: strTl, lineHd :: lineTl) => (strHd :: strTl, lineHd :: lineTl) =>
if isInLimit (strHd, newString, lineHd, newLines) then if isInLimit (strHd, newString, lineHd, newLines) then
(* Fits in limit, so we can add to existing string/line vector.*) (* Fits in limit, so we can add to existing string/line vector.*)
let let
(* VERIFIED TO WORK *)
val _ = print "line 110\n" val _ = print "line 110\n"
val newIdx = curIdx + String.size newString val newIdx = curIdx + String.size newString
val newStrHd = strHd ^ newString val newStrHd = strHd ^ newString
@@ -164,6 +246,7 @@ struct
) )
val newLeftLines = newLinesHd :: lineTl val newLeftLines = newLinesHd :: lineTl
in in
verifyReturn
{ idx = newIdx { idx = newIdx
, line = newLine , line = newLine
, leftStrings = newLeftString , leftStrings = newLeftString
@@ -175,8 +258,10 @@ struct
else else
let let
val _ = print "line 137\n" val _ = print "line 137\n"
(* VERIFIED TO WORK *)
in in
(* Does not fit in limit, so cons instead.*) (* Does not fit in limit, so cons instead.*)
verifyReturn
{ idx = curIdx + String.size newString { idx = curIdx + String.size newString
, line = curLine + Vector.length newLines , line = curLine + Vector.length newLines
, leftStrings = newString :: leftStrings , leftStrings = newString :: leftStrings
@@ -194,7 +279,9 @@ struct
*) *)
let let
val _ = print "line 156\n" val _ = print "line 156\n"
(* VERIFIED TO WORK *)
in in
verifyReturn
{ idx = String.size newString { idx = String.size newString
, line = Vector.length newLines , line = Vector.length newLines
, leftStrings = [newString] , leftStrings = [newString]
@@ -222,9 +309,15 @@ struct
) : t = ) : t =
if idx = prevIdx then if idx = prevIdx then
(* Need to insert at the start of the left list. *) (* Need to insert at the start of the left list. *)
if isInLimit (newString, leftStringsHd, newLines, leftLinesHd) then if
(*
isInLimit (newString, leftStringsHd, newLines, leftLinesHd)
*)
false
then
let let
(* Create new vector, adjusting indices as needed. *) (* Create new vector, adjusting indices as needed. *)
(* VERIFIED TO WORK *)
val _ = print "line 188\n" val _ = print "line 188\n"
val joinedLines = val joinedLines =
Vector.tabulate Vector.tabulate
@@ -237,6 +330,7 @@ struct
+ String.size newString + String.size newString
) )
in in
verifyReturn
{ idx = curIdx + String.size newString { idx = curIdx + String.size newString
, line = curLine + Vector.length newLines , line = curLine + Vector.length newLines
, leftStrings = (newString ^ leftStringsHd) :: leftStringsTl , leftStrings = (newString ^ leftStringsHd) :: leftStringsTl
@@ -248,8 +342,10 @@ struct
else else
(* Just cons everything; no way we can join while staying in limit. *) (* Just cons everything; no way we can join while staying in limit. *)
let let
(* VERIFIED TO WORK *)
val _ = print "line 210\n" val _ = print "line 210\n"
in in
verifyReturn
{ idx = curIdx + String.size newString { idx = curIdx + String.size newString
, line = curLine + Vector.length newLines , line = curLine + Vector.length newLines
, leftStrings = leftStringsHd :: newString :: leftStringsTl , leftStrings = leftStringsHd :: newString :: leftStringsTl
@@ -266,43 +362,52 @@ struct
val strSub1 = String.substring (leftStringsHd, 0, strLength) val strSub1 = String.substring (leftStringsHd, 0, strLength)
val strSub2 = String.substring val strSub2 = String.substring
(leftStringsHd, strLength, String.size leftStringsHd - strLength) (leftStringsHd, strLength, String.size leftStringsHd - strLength)
val midpoint = binSearch (String.size strSub1, leftLinesHd) val midpoint = binSearch (String.size strSub1 - 1, leftLinesHd)
val _ = print ("lines in vec: " ^ lineBreaksToString leftLinesHd ^ "\n")
val _ = print val _ = print
("str size:" ^ Int.toString (Vector.length leftLinesHd) ^ "\n") ("vec size:" ^ Int.toString (Vector.length leftLinesHd) ^ "\n")
val _ = print ("midpoint:" ^ Int.toString (midpoint) ^ "\n") val _ = print ("midpoint:" ^ Int.toString (midpoint) ^ "\n")
in in
if if
isThreeInLimit (strSub1, newString, strSub2, leftLinesHd, newLines) (* isThreeInLimit (strSub1, newString, strSub2, leftLinesHd, newLines)
* *) false
then then
(* Join three strings together. *) (* Join three strings together. *)
let let
(* VERIFIED TO WORK *)
val _ = print "line 233\n" val _ = print "line 233\n"
val joinedString = String.concat [strSub1, newString, strSub2]
val joinedLines = val joinedLines =
if Vector.length leftLinesHd > 0 then
Vector.tabulate Vector.tabulate
( Vector.length leftLinesHd + Vector.length newLines ( Vector.length leftLinesHd + Vector.length newLines
, fn idx => , fn idx =>
if idx < midpoint then if idx <= midpoint then
Vector.sub (leftLinesHd, idx) Vector.sub (leftLinesHd, idx)
else if idx < midpoint + Vector.length newLines then else if idx <= midpoint + Vector.length newLines then
Vector.sub (newLines, idx - midpoint) Vector.sub (newLines, (idx - midpoint) - 1)
+ String.size strSub1 + String.size strSub1
else else
Vector.sub (leftLinesHd, idx - Vector.length newLines) Vector.sub (leftLinesHd, (idx - Vector.length newLines))
+ String.size newString + String.size newString
) )
else
Vector.map (fn el => el + String.size strSub1) newLines
in in
verifyReturn
{ idx = curIdx + String.size newString { idx = curIdx + String.size newString
, line = curLine + Vector.length newLines , line = curLine + Vector.length newLines
, leftStrings = , leftStrings = joinedString :: leftStringsTl
String.concat [strSub1, newString, strSub2] :: leftStringsTl
, leftLines = joinedLines :: leftLinesTl , leftLines = joinedLines :: leftLinesTl
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} }
end end
else if else if
true (*
String.size strSub1 + String.size newString <= stringLimit String.size strSub1 + String.size newString <= stringLimit
andalso midpoint + Vector.length newLines <= vecLimit andalso midpoint + Vector.length newLines <= vecLimit
*)
then then
(* If we can join newString/lines with sub1 while (* If we can join newString/lines with sub1 while
* staying in limit. *) * staying in limit. *)
@@ -311,35 +416,47 @@ struct
val _ = print val _ = print
("vector length: " ^ Int.toString (Vector.length newLines) ^ "\n") ("vector length: " ^ Int.toString (Vector.length newLines) ^ "\n")
val _ = print ("midpoint: " ^ Int.toString (midpoint) ^ "\n") val _ = print ("midpoint: " ^ Int.toString (midpoint) ^ "\n")
val newLeftLines = countLineBreaks (strSub1 ^ newString)
(*
val newLeftLines = val newLeftLines =
Vector.tabulate (midpoint + Vector.length newLines, fn idx => Vector.tabulate (midpoint + Vector.length newLines, fn idx =>
if idx < midpoint then Vector.sub (leftLinesHd, idx) if idx < midpoint then Vector.sub (leftLinesHd, idx)
else Vector.sub (newLines, idx - midpoint) + String.size strSub1) else Vector.sub (newLines, idx - midpoint) + String.size strSub1)
*)
val _ = print "line 275\n" val _ = print "line 275\n"
(*
val newRightLines = VectorSlice.slice (leftLinesHd, midpoint, SOME val newRightLines = VectorSlice.slice (leftLinesHd, midpoint, SOME
(Vector.length leftLinesHd - midpoint)) (Vector.length leftLinesHd - midpoint))
val newRightLines = VectorSlice.vector newRightLines val newRightLines = VectorSlice.vector newRightLines
*)
in in
verifyReturn
{ idx = prevIdx + String.size strSub1 + String.size newString { idx = prevIdx + String.size strSub1 + String.size newString
, line = , line =
(curLine - Vector.length leftLinesHd) (curLine - Vector.length leftLinesHd)
+ Vector.length newLeftLines + Vector.length newLeftLines
, leftStrings = (strSub1 ^ newString) :: leftStringsTl , leftStrings = (strSub1 ^ newString) :: leftStringsTl
, leftLines = newLeftLines :: leftLinesTl , leftLines = countLineBreaks (strSub1 ^ newString) :: leftLinesTl
, rightStrings = strSub2 :: rightStrings , rightStrings = strSub2 :: rightStrings
, rightLines = newRightLines :: rightLines , rightLines = countLineBreaks strSub2 :: rightLines
} }
end end
else if else if
(*
String.size newString + String.size strSub2 <= stringLimit String.size newString + String.size strSub2 <= stringLimit
andalso andalso
(Vector.length leftLinesHd - midpoint) + Vector.length newLines (Vector.length leftLinesHd - midpoint) + Vector.length newLines
<= vecLimit <= vecLimit
*)
false
then then
(* 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" val _ = print "line 292\n"
(*
val newLeftLines = VectorSlice.slice (leftLinesHd, 0, SOME midpoint) val newLeftLines = VectorSlice.slice (leftLinesHd, 0, SOME midpoint)
val newLeftLines = VectorSlice.vector newLeftLines val newLeftLines = VectorSlice.vector newLeftLines
@@ -353,27 +470,39 @@ struct
else else
(Vector.sub (leftLinesHd, idx - Vector.length newLines) (Vector.sub (leftLinesHd, idx - Vector.length newLines)
- String.size strSub1) + String.size newString - String.size strSub1) + String.size newString
) ) *)
in in
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 = newLeftLines :: leftLinesTl , leftLines = countLineBreaks strSub1 :: leftLinesTl
, rightStrings = (newString ^ strSub2) :: rightStrings , rightStrings = (newString ^ strSub2) :: rightStrings
, rightLines = newRightLines :: rightLines , rightLines = countLineBreaks (newString ^ strSub2) :: rightLines
} }
end end
else else
(* Can't join on either side while staying in limit. *) (* Can't join on either side while staying in limit. *)
let let
val _ = print "line 319\n" (* VERIFIED TO WORK *)
val lineSub1 = VectorSlice.slice (leftLinesHd, 0, SOME midpoint) val lineSub1 =
val lineSub1 = VectorSlice.vector lineSub1 if midpoint >= 0 andalso Vector.length leftLinesHd > 0 then
let
val lineSub2 = VectorSlice.slice (leftLinesHd, midpoint, SOME val lineSub1 = VectorSlice.slice
(Vector.length leftLinesHd - midpoint)) (leftLinesHd, 0, SOME (midpoint + 1))
val lineSub2 = VectorSlice.vector lineSub2
in in
VectorSlice.vector lineSub1
end
else
Vector.fromList []
val lineSub2Length =
Vector.length leftLinesHd - Vector.length lineSub1
val lineSub2 = Vector.tabulate (lineSub2Length, fn idx =>
Vector.sub (leftLinesHd, idx + Vector.length lineSub1)
- String.size strSub1)
in
verifyReturn
{ idx = prevIdx + String.size strSub1 + String.size newString { idx = prevIdx + String.size strSub1 + String.size newString
, line = , line =
(curLine - String.size leftStringsHd) + midpoint (curLine - String.size leftStringsHd) + midpoint
@@ -381,7 +510,7 @@ struct
, leftStrings = newString :: strSub1 :: leftStringsTl , leftStrings = newString :: strSub1 :: leftStringsTl
, leftLines = newLines :: lineSub1 :: leftLinesTl , leftLines = newLines :: lineSub1 :: leftLinesTl
, rightStrings = strSub2 :: rightStrings , rightStrings = strSub2 :: rightStrings
, rightLines = lineSub1 :: rightLines , rightLines = lineSub2 :: rightLines
} }
end end
end end
@@ -389,7 +518,7 @@ struct
fun moveLeftAndIns fun moveLeftAndIns
( idx ( idx
, newString , newString
, newLines , newLines: int vector
, curIdx , curIdx
, curLine , curLine
, leftStrings: string list , leftStrings: string list
@@ -412,14 +541,17 @@ struct
* *) * *)
(case (rightStrings, rightLines) of (case (rightStrings, rightLines) of
(rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) => (rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) =>
if if false
(*
isInLimit isInLimit
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd) (leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
then *) then
let let
val _ = print "line 370\n" val _ = print "line 370\n"
val prevLine = curLine - Vector.length leftLinesHd val prevLine = curLine - Vector.length leftLinesHd
val newRightStringsHd = leftStringsHd ^ rightStringsHd val newRightStringsHd = leftStringsHd ^ rightStringsHd
(*
val newRightLinesHd = val newRightLinesHd =
Vector.tabulate Vector.tabulate
( Vector.length leftLinesHd ( Vector.length leftLinesHd
@@ -432,6 +564,8 @@ struct
(rightLinesHd, idx - Vector.length leftLinesHd) (rightLinesHd, idx - Vector.length leftLinesHd)
+ String.size leftStringsHd + String.size leftStringsHd
) )
*)
val newRightLinesHd = countLineBreaks newRightStringsHd
in in
moveLeftAndIns moveLeftAndIns
( idx ( idx
@@ -492,6 +626,7 @@ struct
| (_, _) => | (_, _) =>
(* Left list is empty, so need to cons or join. (* Left list is empty, so need to cons or join.
* Just set left string/list as newString/newLines. *) * Just set left string/list as newString/newLines. *)
verifyReturn
{ idx = String.size newString { idx = String.size newString
, line = Vector.length newLines , line = Vector.length newLines
, leftStrings = [newString] , leftStrings = [newString]
@@ -523,6 +658,8 @@ struct
let let
val _ = print "line 474\n" val _ = print "line 474\n"
val newRightStringsHd = rightStringsHd ^ newString val newRightStringsHd = rightStringsHd ^ newString
val newRightLinesHd = countLineBreaks newRightStringsHd
(*
val newRightLinesHd = val newRightLinesHd =
Vector.tabulate Vector.tabulate
( Vector.length newLines + Vector.length rightLinesHd ( Vector.length newLines + Vector.length rightLinesHd
@@ -533,13 +670,15 @@ struct
Vector.sub (newLines, idx - Vector.length rightLinesHd) Vector.sub (newLines, idx - Vector.length rightLinesHd)
+ String.size rightStringsHd + String.size rightStringsHd
) )
*)
in in
verifyReturn
{ idx = curIdx { idx = curIdx
, line = curLine , line = curLine
, leftStrings = leftStrings , leftStrings = leftStrings
, leftLines = leftLines , leftLines = leftLines
, rightStrings = newRightStringsHd :: rightStringsTl , rightStrings = newRightStringsHd :: rightStringsTl
, rightLines = newRightLinesHd :: rightLinesTl , rightLines = countLineBreaks newRightStringsHd :: rightLinesTl
} }
end end
else else
@@ -548,6 +687,7 @@ struct
let let
val _ = print "line 498\n" val _ = print "line 498\n"
in in
verifyReturn
{ idx = curIdx { idx = curIdx
, line = curLine , line = curLine
, leftStrings = leftStrings , leftStrings = leftStrings
@@ -563,15 +703,17 @@ struct
val strSub1 = String.substring (rightStringsHd, 0, strLength) val strSub1 = String.substring (rightStringsHd, 0, strLength)
val strSub2 = String.substring val strSub2 = String.substring
(rightStringsHd, strLength, String.size rightStringsHd - strLength) (rightStringsHd, strLength, String.size rightStringsHd - strLength)
val midpoint = binSearch (String.size strSub1, rightLinesHd) val midpoint = binSearch (String.size strSub1 - 1, rightLinesHd)
in in
if if
isThreeInLimit (strSub1, newString, strSub2, rightLinesHd, newLines) isThreeInLimit (strSub1, newString, strSub2, rightLinesHd, newLines)
then then
(* Join three strings together. *) (* Join three strings together. *)
let let
val _ = print "line 520\n" val _ = print "line 573\n"
val newRightStringsHd = String.concat [strSub1, newString, strSub2] val newRightStringsHd = String.concat [strSub1, newString, strSub2]
(*
val newRightLinesHd = val newRightLinesHd =
Vector.tabulate Vector.tabulate
( Vector.length rightLinesHd + Vector.length newLines ( Vector.length rightLinesHd + Vector.length newLines
@@ -579,24 +721,43 @@ struct
if idx < midpoint then if idx < midpoint then
Vector.sub (rightLinesHd, idx) Vector.sub (rightLinesHd, idx)
else if idx < midpoint + Vector.length newLines then else if idx < midpoint + Vector.length newLines then
Vector.sub (newLines, idx - midpoint) let
+ String.size strSub1 val result =
else Vector.sub (newLines, idx - midpoint) + String.size
Vector.sub (rightLinesHd, idx - Vector.length newLines) strSub1
+ String.size newString val _ = print "line 598\n"
) val _ = print ("result: " ^ Int.toString result ^ "\n")
in in
result
end
else
let
val result =
Vector.sub
(rightLinesHd, idx - Vector.length newLines)
+ String.size newString
val _ = print "line 606\n"
val _ = print ("result: " ^ Int.toString result ^ "\n")
in
result
end
) *)
in
verifyReturn
{ idx = curIdx { idx = curIdx
, line = curLine , line = curLine
, leftStrings = leftStrings , leftStrings = leftStrings
, leftLines = leftLines , leftLines = leftLines
, rightStrings = newRightStringsHd :: rightStringsTl , rightStrings = newRightStringsHd :: rightStringsTl
, rightLines = newRightLinesHd :: rightLinesTl , rightLines = countLineBreaks newRightStringsHd :: rightLinesTl
} }
end end
else if else if
(*
String.size strSub1 + String.size newString <= stringLimit String.size strSub1 + String.size newString <= stringLimit
andalso midpoint + Vector.length newLines <= vecLimit andalso midpoint + Vector.length newLines <= vecLimit
*)
false
then then
(* If we can join newString/lines with sub1 while (* If we can join newString/lines with sub1 while
* staying in limit. *) * staying in limit. *)
@@ -604,36 +765,45 @@ struct
(* strSub1 ^ newString is placed on the left list. *) (* strSub1 ^ newString is placed on the left list. *)
val _ = print "line 552\n" val _ = print "line 552\n"
val newLeftStringsHd = strSub1 ^ newString val newLeftStringsHd = strSub1 ^ newString
(*
val newLeftLinesHd = val newLeftLinesHd =
Vector.tabulate (Vector.length newLines + midpoint, fn idx => Vector.tabulate (Vector.length newLines + midpoint, fn idx =>
if idx < midpoint then Vector.sub (rightLinesHd, idx) if idx < midpoint then Vector.sub (rightLinesHd, idx)
else Vector.sub (newLines, idx - midpoint) + String.size strSub1) else Vector.sub (newLines, idx - midpoint) + String.size strSub1)
*)
val _ = print "line 584\n" val _ = print "line 584\n"
(*
val newRightLinesHd = val newRightLinesHd =
VectorSlice.slice (rightLinesHd, midpoint, SOME VectorSlice.slice (rightLinesHd, midpoint, SOME
(Vector.length rightLinesHd - midpoint)) (Vector.length rightLinesHd - midpoint))
val newRightLinesHd = VectorSlice.vector newRightLinesHd val newRightLinesHd = VectorSlice.vector newRightLinesHd *)
in in
verifyReturn
{ idx = curIdx + String.size newLeftStringsHd { idx = curIdx + String.size newLeftStringsHd
, line = curLine + Vector.length newLeftLinesHd , line =
curLine + Vector.length (countLineBreaks newLeftStringsHd)
, leftStrings = newLeftStringsHd :: leftStrings , leftStrings = newLeftStringsHd :: leftStrings
, leftLines = newLeftLinesHd :: leftLines , leftLines = countLineBreaks newLeftStringsHd :: leftLines
, rightStrings = strSub2 :: rightStringsTl , rightStrings = strSub2 :: rightStringsTl
, rightLines = newRightLinesHd :: rightLinesTl , rightLines = countLineBreaks strSub2 :: rightLinesTl
} }
end end
else if else if
(*
String.size newString + String.size strSub2 <= stringLimit String.size newString + String.size strSub2 <= stringLimit
andalso andalso
(Vector.length rightLinesHd - midpoint) + Vector.length newLines (Vector.length rightLinesHd - midpoint) + Vector.length newLines
<= vecLimit <= vecLimit
*)
false
then then
(* 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 581\n" val _ = print "line 581\n"
val newRightStringsHd = newString ^ strSub2 val newRightStringsHd = newString ^ strSub2
(*
val newRightLinesHd = val newRightLinesHd =
Vector.tabulate Vector.tabulate
( Vector.length newLines + Vector.length rightLinesHd - midpoint ( Vector.length newLines + Vector.length rightLinesHd - midpoint
@@ -644,30 +814,48 @@ struct
Vector.sub (rightLinesHd, idx - Vector.length newLines) Vector.sub (rightLinesHd, idx - Vector.length newLines)
+ String.size newString + String.size newString
) )
val newLeftLinesHd = val newLeftLinesHd =
VectorSlice.slice (rightLinesHd, 0, SOME midpoint) VectorSlice.slice (rightLinesHd, 0, SOME midpoint)
val newLeftLinesHd = VectorSlice.vector newLeftLinesHd val newLeftLinesHd = VectorSlice.vector newLeftLinesHd
*)
in in
verifyReturn
{ idx = curIdx + String.size strSub1 { idx = curIdx + String.size strSub1
, line = curLine + Vector.length newLeftLinesHd , line = curLine + Vector.length (countLineBreaks strSub1)
, leftStrings = strSub1 :: leftStrings , leftStrings = strSub1 :: leftStrings
, leftLines = newLeftLinesHd :: leftLines , leftLines = countLineBreaks strSub1 :: leftLines
, rightStrings = newRightStringsHd :: rightStringsTl , rightStrings = newRightStringsHd :: rightStringsTl
, rightLines = newRightLinesHd :: rightLinesTl , rightLines = countLineBreaks newRightStringsHd :: rightLinesTl
} }
end end
else else
(* Can't join on either side while staying in limit. *) (* Can't join on either side while staying in limit. *)
let let
(* VERIFIED TO WORK *)
val _ = print "line 608\n" val _ = print "line 608\n"
val lineSub1 = VectorSlice.slice (rightLinesHd, 0, SOME midpoint) val lineSub1 =
val lineSub1 = VectorSlice.vector lineSub1 if midpoint >= 0 andalso Vector.length rightLinesHd > 0 then
val lineSub2 = VectorSlice.slice (rightLinesHd, midpoint, SOME let
(Vector.length rightLinesHd - midpoint)) val lineSub1 = VectorSlice.slice
val lineSub2 = VectorSlice.vector lineSub2 (rightLinesHd, 0, SOME (midpoint + 1))
in in
VectorSlice.vector lineSub1
end
else
Vector.fromList []
val lineSub2Length =
Vector.length rightLinesHd - Vector.length lineSub1
val lineSub2 = Vector.tabulate (lineSub2Length, fn idx =>
Vector.sub (rightLinesHd, idx + Vector.length lineSub1)
- String.size strSub1)
in
verifyReturn
{ idx = curIdx + String.size strSub1 + String.size newString { idx = curIdx + String.size strSub1 + String.size newString
, line = curLine + Vector.length lineSub1 + Vector.length newLines , line =
curLine + Vector.length (countLineBreaks newString)
+ Vector.length lineSub1
, leftStrings = newString :: strSub1 :: leftStrings , leftStrings = newString :: strSub1 :: leftStrings
, leftLines = newLines :: lineSub1 :: leftLines , leftLines = newLines :: lineSub1 :: leftLines
, rightStrings = strSub2 :: rightStringsTl , rightStrings = strSub2 :: rightStringsTl
@@ -697,13 +885,17 @@ struct
(case (leftStrings, leftLines) of (case (leftStrings, leftLines) of
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) => (leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
if if
(*
isInLimit isInLimit
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd) (leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
*)
false
then then
let let
val _ = print "line 650\n" val _ = print "line 650\n"
val nextLine = curLine + Vector.length rightLinesHd val nextLine = curLine + Vector.length rightLinesHd
val newLeftStringsHd = leftStringsHd ^ rightStringsHd val newLeftStringsHd = leftStringsHd ^ rightStringsHd
(*
val newLeftLinesHd = val newLeftLinesHd =
Vector.tabulate Vector.tabulate
( Vector.length leftLinesHd ( Vector.length leftLinesHd
@@ -715,7 +907,8 @@ struct
Vector.sub Vector.sub
(rightLinesHd, idx - Vector.length leftLinesHd) (rightLinesHd, idx - Vector.length leftLinesHd)
+ String.size leftStringsHd + String.size leftStringsHd
) ) *)
val newLeftLinesHd = countLineBreaks newLeftStringsHd
in in
moveRightAndIns moveRightAndIns
( idx ( idx
@@ -777,6 +970,7 @@ struct
let let
val _ = print "line 723\n" val _ = print "line 723\n"
in in
verifyReturn
{ idx = curIdx { idx = curIdx
, line = curLine , line = curLine
, leftStrings = leftStrings , leftStrings = leftStrings

View File

@@ -67,7 +67,7 @@ struct
if prevChar = #"\r" then if prevChar = #"\r" then
helpCountLineBreaks (pos - 2, (pos - 1) :: acc, str) helpCountLineBreaks (pos - 2, (pos - 1) :: acc, str)
else else
helpCountLineBreaks (pos - 2, pos :: acc, str) helpCountLineBreaks (pos - 1, pos :: acc, str)
end end
else if chr = #"\r" then else if chr = #"\r" then
helpCountLineBreaks (pos - 1, pos :: acc, str) helpCountLineBreaks (pos - 1, pos :: acc, str)

View File

@@ -54,6 +54,7 @@ fun compareTxns arr =
fun main () = fun main () =
let let
val (rope, gap) = compareTxns SvelteComponent.txns val (rope, gap) = compareTxns SvelteComponent.txns
val _ = print "string contents are equal\n"
val _ = LineGap.verifyLines gap val _ = LineGap.verifyLines gap
(* (*
val _ = compareTxns Rust.txns val _ = compareTxns Rust.txns