delete some dead code

This commit is contained in:
2025-08-06 00:30:50 +01:00
parent f0f28a1318
commit e06a27d5ad
7 changed files with 87 additions and 231 deletions

View File

@@ -392,8 +392,7 @@ struct
val searchString = #searchString app
val buffer = LineGap.delete (cursorIdx, 1, buffer)
val (buffer, searchList) =
SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
val cursorIdx =
if
@@ -409,8 +408,7 @@ struct
val searchString = #searchString app
val buffer = LineGap.delete (cursorIdx, 1, buffer)
val (buffer, searchList) =
SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
in
helpRemoveChr (app, buffer, searchList, cursorIdx, count - 1)
end
@@ -437,7 +435,7 @@ struct
val buffer = LineGap.delete (low, length, buffer)
val searchString = #searchString app
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
(* If we have deleted from the buffer so that cursorIdx
* is no longer a valid idx,
@@ -473,7 +471,7 @@ struct
val buffer = LineGap.delete (low, length, buffer)
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
val buffer = LineGap.goToIdx (low, buffer)
in
@@ -502,7 +500,7 @@ struct
(* delete from searchList and map *)
val searchString = #searchString app
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
in
helpRemoveChr (app, buffer, searchList, cursorIdx, 1)
end
@@ -519,7 +517,7 @@ struct
val length = finishIdx - startIdx
val buffer = LineGap.delete (startIdx, length, buffer)
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
val buffer = LineGap.goToIdx (startIdx, buffer)
in
@@ -534,7 +532,7 @@ struct
val buffer = LineGap.delete (low, length, buffer)
val searchString = #searchString app
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
val buffer = LineGap.goToIdx (low, buffer)
in
@@ -585,7 +583,7 @@ struct
val length = high - low
val buffer = LineGap.delete (low, length, buffer)
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
in
Finish.buildTextAndClear (app, buffer, low, searchList)
end
@@ -600,7 +598,7 @@ struct
val buffer = LineGap.delete (low, length, buffer)
val searchString = #searchString app
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
in
buildTextAndClearAfterChr (app, buffer, low, searchList)
end
@@ -633,7 +631,7 @@ struct
app
val buffer = LineGap.delete (0, cursorIdx, buffer)
val (buffer, searchList) = SearchLineGap.build (buffer, searchString)
val (buffer, searchList) = SearchList.build (buffer, searchString)
val cursorIdx = 0
val startLine = 0

View File

@@ -1,154 +1,96 @@
signature SEARCH_LIST =
sig
type t = {left: int vector list, right: int vector list}
val empty: t
val exists: int * t -> bool
val insert: int * t -> t
val append: int * t -> t
val delete: int * int * string * t -> t
val goToNum: int * t -> t
val mapFrom: int * int * t -> t
val toVector: t -> int vector
val toString: t -> string
end
structure SearchList: SEARCH_LIST =
structure SearchList =
struct
structure IntSet =
MakeGapSet
(struct
type key = int
val maxNodeSize = 32
fun l (a: int, b) = a < b
fun eq (a: int, b) = a = b
fun g (a: int, b) = a > b
fun l (a, b: int) = a < b
fun eq (a, b: int) = a = b
fun g (a, b: int) = a > b
end)
type t = IntSet.t
fun helpToVector (left, right) =
case left of
hd :: tl => helpToVector (tl, hd :: right)
| [] => Vector.concat right
(* for testing *)
fun toVector {left, right} = helpToVector (left, right)
val empty = IntSet.empty
fun insert (num, set) =
let val () = print ("adding num: " ^ Int.toString num ^ "\n")
in IntSet.add (num, set)
end
val append = IntSet.add
val goToNum = IntSet.moveTo
fun delete (start, length, searchString, set) =
if length > 0 then
fun cons (num, acc) =
let
val num = Vector.fromList [num]
in
case acc of
hd :: tl =>
if Vector.length hd < 32 then (Vector.concat [num, hd]) :: tl
else num :: acc
| [] => num :: acc
end
fun searchStep (pos, hd, absIdx, tl, acc, searchPos, searchString) =
if searchPos < 0 then
cons (absIdx + 1, acc)
else if pos < 0 then
case tl of
hd :: tl =>
searchStep
(String.size hd - 1, hd, absIdx, tl, acc, searchPos, searchString)
| [] => acc
else
let
val firstVec = toVector set
val finish = start + length
val start = start - String.size searchString + 1
val result = IntSet.removeMany (start, finish, set)
val secondVec = toVector result
val () = print
("delete start has " ^ Int.toString (Vector.length firstVec)
^ "elements\n")
val () = print
("delete result has " ^ Int.toString (Vector.length secondVec)
^ "elements\n")
val bufferChr = String.sub (hd, pos)
val searchChr = String.sub (searchString, searchPos)
in
result
if bufferChr = searchChr then
searchStep
(pos - 1, hd, absIdx - 1, tl, acc, searchPos - 1, searchString)
else
acc
end
fun loopSearch (pos, hd, absIdx, tl, acc, searchString) =
if pos < 0 then
case tl of
hd :: tl =>
loopSearch (String.size hd - 1, hd, absIdx, tl, acc, searchString)
| [] => acc
else
let
val acc = searchStep
(pos, hd, absIdx, tl, acc, String.size searchString - 1, searchString)
in
loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString)
end
(* Prerequisite: move buffer/LineGap to end *)
fun search (buffer: LineGap.t, searchString) =
let
val acc =
if String.size searchString = 0 then
[]
else
let
val {leftStrings, idx = absIdx, ...} = buffer
in
case leftStrings of
hd :: tl =>
loopSearch
(String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
| [] => []
end
in
{left = [], right = acc}
end
fun build (buffer, searchString) =
if String.size searchString > 0 then
let
val buffer = LineGap.goToEnd buffer
val searchList = search (buffer, searchString)
in
(buffer, searchList)
end
else
set
fun isLessThanTarget (v1, v2) =
Vector.length v1 + Vector.length v2 <= 32
fun joinEndOfLeft (new, left) =
case left of
hd :: tail =>
if isLessThanTarget (new, hd) then
let val newHd = Vector.concat [hd, new]
in newHd :: tail
end
else
new :: left
| [] => new :: left
(* go all the way to the end of the list, mapping each hd,
* joining the hd to the left,
* and return when we have reached the end *)
fun mapRight (mapBy, left, right) =
case right of
hd :: tl =>
let val newHd = Vector.map (fn el => el + mapBy) hd
in mapRight (mapBy, joinEndOfLeft (newHd, left), tl)
end
| [] => {left = left, right = right}
fun moveRightAndMap (from, mapBy, left, right) =
case right of
hd :: tl =>
let
val lastIdx = Vector.length hd - 1
val last = Vector.sub (hd, lastIdx)
in
if from > last then
moveRightAndMap (from, mapBy, joinEndOfLeft (hd, left), tl)
else if from < last then
(* need to map in middle *)
let
val startIdx = BinSearch.equalOrMore (from, hd)
val mapEl = Vector.sub (hd, startIdx)
val newHd =
Vector.map (fn el => if el < from then el else el + mapBy) hd
in
mapRight (mapBy, joinEndOfLeft (newHd, left), tl)
end
else
(* from = last *)
let
val newHd =
Vector.map (fn el => if el < from then el else el + mapBy) hd
in
mapRight (mapBy, joinEndOfLeft (newHd, left), tl)
end
end
| [] => {left = left, right = right}
fun mapFrom (num, mapBy, lst) =
let
(* goToNum always places vector where num was found to the right list *)
val () = print ("mapping by " ^ Int.toString num ^ "\n")
val {left, right} = goToNum (0, lst)
in
moveRightAndMap (num, 0, left, right)
end
val exists = IntSet.exists
fun toString {left, right} =
let
val vec = toVector {left = left, right = right}
val () = print
("toString has " ^ Int.toString (Vector.length vec) ^ "elements\n")
val strList =
Vector.foldr (fn (num, acc) => Int.toString num :: acc) [] vec
in
""
end
(buffer, empty)
end

View File

@@ -1,79 +0,0 @@
structure SearchLineGap =
struct
fun cons (num, acc) =
let
val num = Vector.fromList [num]
in
case acc of
hd :: tl =>
if Vector.length hd < 32 then (Vector.concat [num, hd]) :: tl
else num :: acc
| [] => num :: acc
end
fun searchStep (pos, hd, absIdx, tl, acc, searchPos, searchString) =
if searchPos < 0 then
cons (absIdx + 1, acc)
else if pos < 0 then
case tl of
hd :: tl =>
searchStep
(String.size hd - 1, hd, absIdx, tl, acc, searchPos, searchString)
| [] => acc
else
let
val bufferChr = String.sub (hd, pos)
val searchChr = String.sub (searchString, searchPos)
in
if bufferChr = searchChr then
searchStep
(pos - 1, hd, absIdx - 1, tl, acc, searchPos - 1, searchString)
else
acc
end
fun loopSearch (pos, hd, absIdx, tl, acc, searchString) =
if pos < 0 then
case tl of
hd :: tl =>
loopSearch (String.size hd - 1, hd, absIdx, tl, acc, searchString)
| [] => acc
else
let
val acc = searchStep
(pos, hd, absIdx, tl, acc, String.size searchString - 1, searchString)
in
loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString)
end
(* Prerequisite: move buffer/LineGap to end *)
fun search (buffer: LineGap.t, searchString) =
let
val acc =
if String.size searchString = 0 then
[]
else
let
val {leftStrings, idx = absIdx, ...} = buffer
in
case leftStrings of
hd :: tl =>
loopSearch
(String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
| [] => []
end
in
{left = [], right = acc}
end
fun build (buffer, searchString) =
if String.size searchString > 0 then
let
val buffer = LineGap.goToEnd buffer
val searchList = search (buffer, searchString)
in
(buffer, searchList)
end
else
(buffer, SearchList.empty)
end