progress on fixing exceptions with regard to vector

This commit is contained in:
2024-06-30 01:32:59 +01:00
parent 6af253eed9
commit 75aba5e8e1
2 changed files with 20 additions and 6 deletions

View File

@@ -2,6 +2,9 @@ structure LineGap =
struct struct
local local
fun helpCountLineBreaks (pos, acc, str) = fun helpCountLineBreaks (pos, acc, str) =
let
val _ = print ("count pos: " ^ Int.toString pos ^ "\n")
in
if pos < 0 then if pos < 0 then
Vector.fromList acc Vector.fromList acc
else else
@@ -26,6 +29,7 @@ struct
else else
helpCountLineBreaks (pos - 1, acc, str) helpCountLineBreaks (pos - 1, acc, str)
end end
end
in in
fun countLineBreaks str = fun countLineBreaks str =
helpCountLineBreaks (String.size str - 1, [], str) helpCountLineBreaks (String.size str - 1, [], str)
@@ -85,7 +89,7 @@ struct
helpBinSearch (findNum, lines, low, mid - 1) helpBinSearch (findNum, lines, low, mid - 1)
end end
else else
mid Int.max (0, mid)
end end
in in
fun binSearch (findNum, lines) = fun binSearch (findNum, lines) =
@@ -224,6 +228,8 @@ struct
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, leftLinesHd)
val _ = print ("str size:" ^ Int.toString (Vector.length leftLinesHd) ^ "\n")
val _ = print ("midpoint:" ^ Int.toString (midpoint) ^ "\n")
in in
if if
isThreeInLimit (strSub1, newString, strSub2, leftLinesHd, newLines) isThreeInLimit (strSub1, newString, strSub2, leftLinesHd, newLines)
@@ -261,11 +267,15 @@ 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
val _ = print "line 264\n" val _ = print "line 268\n"
val _ = print ("vector length: " ^ Int.toString (Vector.length newLines ) ^ "\n")
val _ = print ("midpoint: " ^ Int.toString (
midpoint) ^ "\n")
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 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
@@ -553,12 +563,16 @@ struct
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
else Vector.sub (newLines, idx - midpoint) + String.size strSub1) Vector.sub (rightLinesHd, idx)
else
Vector.sub (newLines, accessIdx) + String.size strSub1
)
val _ = print "line 584\n"
val newRightLinesHd = val newRightLinesHd =
VectorSlice.slice (rightLinesHd, midpoint, SOME VectorSlice.slice (rightLinesHd, midpoint, SOME
(Vector.length rightStringsHd - midpoint)) (Vector.length rightLinesHd - midpoint))
val newRightLinesHd = VectorSlice.vector newRightLinesHd val newRightLinesHd = VectorSlice.vector newRightLinesHd
in in
{ idx = curIdx + String.size newLeftStringsHd { idx = curIdx + String.size newLeftStringsHd
@@ -779,7 +793,7 @@ struct
fun insert (idx, newString, buffer: t) = fun insert (idx, newString, buffer: t) =
let let
val newLines = Vector.fromList [] val newLines = countLineBreaks newString
in in
ins ins
( idx ( idx

Binary file not shown.