address a few things I forgot in line_gap.sml

This commit is contained in:
2024-07-03 17:41:04 +01:00
parent 3a954ceb4c
commit 58a56e9685

View File

@@ -172,7 +172,7 @@ struct
else reverseLinearSearch (findNum, idx, lines) else reverseLinearSearch (findNum, idx, lines)
end end
fun helpBinSearch (findNum, lines, low, high, prevLow, prevHigh) = fun helpBinSearch (findNum, lines, low, high) =
let let
val mid = low + ((high - low) div 2) val mid = low + ((high - low) div 2)
in in
@@ -183,34 +183,17 @@ struct
if midVal = findNum then if midVal = findNum then
(print "return 173\n"; mid) (print "return 173\n"; mid)
else if midVal < findNum then else if midVal < findNum then
helpBinSearch (findNum, lines, mid + 1, high, low, high) helpBinSearch (findNum, lines, mid + 1, high)
else else
helpBinSearch (findNum, lines, low, mid - 1, low, high) helpBinSearch (findNum, lines, low, mid - 1)
end end
else else
let reverseLinearSearch (findNum, mid, lines)
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 if Vector.length lines = 0 then 0
0 else helpBinSearch (findNum, lines, 0, Vector.length lines - 1)
else
helpBinSearch
( findNum
, lines
, 0
, Vector.length lines - 1
, 0
, Vector.length lines - 1
)
end end
fun insWhenIdxAndCurIdxAreEqual fun insWhenIdxAndCurIdxAreEqual
@@ -688,7 +671,16 @@ struct
(* VERIFIED TO WORK *) (* VERIFIED TO WORK *)
val _ = print "line 474\n" val _ = print "line 474\n"
val newRightStringsHd = rightStringsHd ^ newString val newRightStringsHd = rightStringsHd ^ newString
val newRightLinesHd = countLineBreaks newRightStringsHd val newRightLinesHd =
Vector.tabulate
( Vector.length rightLinesHd + Vector.length newLines
, fn idx =>
if idx < Vector.length rightLinesHd then
Vector.sub (rightLinesHd, idx)
else
Vector.sub (newLines, idx - Vector.length rightLinesHd)
+ String.size rightStringsHd
)
in in
verifyReturn verifyReturn
{ idx = curIdx { idx = curIdx
@@ -777,7 +769,6 @@ 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 =
if midpoint >= 0 then if midpoint >= 0 then
(* Implicit: a binSearch match was found. *) (* Implicit: a binSearch match was found. *)
@@ -842,7 +833,6 @@ struct
Vector.fromList [] Vector.fromList []
val newRightStringsHd = newString ^ strSub2 val newRightStringsHd = newString ^ strSub2
val newRightLinesHd = val newRightLinesHd =
Vector.tabulate Vector.tabulate
( (Vector.length newLines + Vector.length rightLinesHd) ( (Vector.length newLines + Vector.length rightLinesHd)
@@ -893,7 +883,7 @@ struct
verifyReturn verifyReturn
{ idx = curIdx + String.size strSub1 + String.size newString { idx = curIdx + String.size strSub1 + String.size newString
, line = , line =
curLine + Vector.length (countLineBreaks newString) curLine + Vector.length newLines
+ Vector.length lineSub1 + Vector.length lineSub1
, leftStrings = newString :: strSub1 :: leftStrings , leftStrings = newString :: strSub1 :: leftStrings
, leftLines = newLines :: lineSub1 :: leftLines , leftLines = newLines :: lineSub1 :: leftLines