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