wrap helper functions to 'insert' inside 'local ... in ... end' to semantically convey that these helper functions are never used elsewhere

This commit is contained in:
2024-07-04 03:39:00 +01:00
parent c6fef0499e
commit ca3dab5193

View File

@@ -107,6 +107,8 @@ struct
else helpBinSearch (findNum, lines, 0, Vector.length lines - 1) else helpBinSearch (findNum, lines, 0, Vector.length lines - 1)
end end
(* Helper functions for insertion operation. *)
local
fun insWhenIdxAndCurIdxAreEqual fun insWhenIdxAndCurIdxAreEqual
( newString ( newString
, newLines , newLines
@@ -247,7 +249,8 @@ struct
Vector.sub (newLines, (idx - midpoint) - 1) 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 else
@@ -271,7 +274,8 @@ struct
(* Implicit: a binSearch match was found. *) (* Implicit: a binSearch match was found. *)
let let
val newLeftLinesLength = midpoint + 1 + Vector.length newLines val newLeftLinesLength = midpoint + 1 + Vector.length newLines
val newLeftLines = Vector.tabulate (newLeftLinesLength, fn idx => val newLeftLines =
Vector.tabulate (newLeftLinesLength, fn idx =>
if idx <= midpoint then if idx <= midpoint then
Vector.sub (leftLinesHd, idx) Vector.sub (leftLinesHd, idx)
else else
@@ -414,10 +418,16 @@ struct
* under the limit. * under the limit.
* *) * *)
(case (rightStrings, rightLines) of (case (rightStrings, rightLines) of
(rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) => ( rightStringsHd :: rightStringsTl
, rightLinesHd :: rightLinesTl
) =>
if if
isInLimit isInLimit
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd) ( leftStringsHd
, rightStringsHd
, leftLinesHd
, rightLinesHd
)
then then
let let
val prevLine = curLine - Vector.length leftLinesHd val prevLine = curLine - Vector.length leftLinesHd
@@ -432,8 +442,9 @@ struct
Vector.sub (leftLinesHd, idx) Vector.sub (leftLinesHd, idx)
else else
Vector.sub Vector.sub
(rightLinesHd, idx - Vector.length leftLinesHd) ( rightLinesHd
+ String.size leftStringsHd , idx - Vector.length leftLinesHd
) + String.size leftStringsHd
) )
in in
moveLeftAndIns moveLeftAndIns
@@ -568,7 +579,8 @@ struct
then then
(* Join three strings together. *) (* Join three strings together. *)
let let
val newRightStringsHd = String.concat [strSub1, newString, strSub2] val newRightStringsHd =
String.concat [strSub1, newString, strSub2]
val newRightLinesHd = val newRightLinesHd =
if Vector.length rightLinesHd > 0 then if Vector.length rightLinesHd > 0 then
Vector.tabulate Vector.tabulate
@@ -743,7 +755,11 @@ struct
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) => (leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
if if
isInLimit isInLimit
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd) ( leftStringsHd
, rightStringsHd
, leftLinesHd
, rightLinesHd
)
then then
let let
val nextLine = curLine + Vector.length rightLinesHd val nextLine = curLine + Vector.length rightLinesHd
@@ -757,8 +773,9 @@ struct
Vector.sub (leftLinesHd, idx) Vector.sub (leftLinesHd, idx)
else else
Vector.sub Vector.sub
(rightLinesHd, idx - Vector.length leftLinesHd) ( rightLinesHd
+ String.size leftStringsHd , idx - Vector.length leftLinesHd
) + String.size leftStringsHd
) )
in in
moveRightAndIns moveRightAndIns
@@ -873,7 +890,7 @@ struct
, rightStrings , rightStrings
, rightLines , rightLines
) )
in
fun insert (idx, newString, buffer: t) = fun insert (idx, newString, buffer: t) =
let let
val newLines = countLineBreaks newString val newLines = countLineBreaks newString
@@ -890,6 +907,7 @@ struct
, #rightLines buffer , #rightLines buffer
) )
end end
end
(* TEST CODE *) (* TEST CODE *)