From e06a27d5adcff67251dbfaa1eaf81840853e0e21 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Wed, 6 Aug 2025 00:30:50 +0100 Subject: [PATCH] delete some dead code --- fcore/app-update.sml | 22 ++-- fcore/search-list.sml | 210 +++++++++++-------------------- fcore/search/search-line-gap.sml | 79 ------------ shell/shell.sml | 2 +- shell/update-thread.sml | 3 - shf-tests.mlb | 1 - shf.mlb | 1 - 7 files changed, 87 insertions(+), 231 deletions(-) delete mode 100644 fcore/search/search-line-gap.sml diff --git a/fcore/app-update.sml b/fcore/app-update.sml index c73ae6f..3ccee0d 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -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 diff --git a/fcore/search-list.sml b/fcore/search-list.sml index 2291c97..1e50202 100644 --- a/fcore/search-list.sml +++ b/fcore/search-list.sml @@ -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 diff --git a/fcore/search/search-line-gap.sml b/fcore/search/search-line-gap.sml deleted file mode 100644 index fa9e357..0000000 --- a/fcore/search/search-line-gap.sml +++ /dev/null @@ -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 diff --git a/shell/shell.sml b/shell/shell.sml index 6433a3c..f6c325b 100644 --- a/shell/shell.sml +++ b/shell/shell.sml @@ -69,7 +69,7 @@ struct let val searchString = "val " val (buffer, searchList) = - SearchLineGap.build (#buffer app, searchString) + SearchList.build (#buffer app, searchString) val buffer = LineGap.goToStart buffer in AppWith.searchList (app, searchList, buffer, searchString) diff --git a/shell/update-thread.sml b/shell/update-thread.sml index 4358524..1dfdb20 100644 --- a/shell/update-thread.sml +++ b/shell/update-thread.sml @@ -33,9 +33,6 @@ struct val app = AppUpdate.update (app, inputMsg) handle e => ExceptionLogger.log e - val searchList = #searchList app - val searchList = SearchList.toString searchList ^ "\n" - val () = sendMsgs (#msgs app, drawMailbox) in loop (app, inputMailbox, drawMailbox) diff --git a/shf-tests.mlb b/shf-tests.mlb index 5a6af1e..8f3fa4f 100644 --- a/shf-tests.mlb +++ b/shf-tests.mlb @@ -12,7 +12,6 @@ message-types/mailbox-type.sml fcore/bin-search.sml fcore/search-list.sml -fcore/search/search-line-gap.sml fcore/app-type.sml fcore/app-with.sml diff --git a/shf.mlb b/shf.mlb index 3be7291..9ffb928 100644 --- a/shf.mlb +++ b/shf.mlb @@ -12,7 +12,6 @@ message-types/mailbox-type.sml fcore/bin-search.sml fcore/search-list.sml -fcore/search/search-line-gap.sml fcore/app-type.sml fcore/app-with.sml