From a4ac1b9ae0056daf880a9138243fcd29e2a065f1 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 4 Aug 2025 12:08:35 +0100 Subject: [PATCH] add function for testing search-list.sml --- fcore/search-list.sml | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/fcore/search-list.sml b/fcore/search-list.sml index 85b5312..79a2a82 100644 --- a/fcore/search-list.sml +++ b/fcore/search-list.sml @@ -10,26 +10,15 @@ sig val goToNum: int * t -> t val mapFrom: int * int * t -> t - val printlst: t -> unit + + val toVector: t -> int vector + val toString: t -> string end -structure SearchList :> SEARCH_LIST = +structure SearchList : SEARCH_LIST = struct type t = {left: int vector list, right: int vector list} - (* temp function for testing *) - fun printlst {left, right} = - let - val left = List.rev left - val lst = List.concat [left, right] - val v = Vector.concat lst - val _ = print "\nstart print list:\n" - val _ = Vector.map (fn el => print (" " ^ Int.toString el ^ ",")) v - val _ = print "\nend print list\n" - in - () - end - (* clojure's persistent vectors contain arrays of length 32 * and this data structure is similar to that, so we also use 32 *) val targetLength = 32 @@ -625,4 +614,21 @@ struct else helpExistsLeft (num, left) end | [] => helpExistsLeft (num, left) + + 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) + + fun toString {left, right} = + let + val vec = toVector {left = left, right = right} + + val strList = Vector.foldr (fn (num, acc) => Int.toString num :: acc) [] vec + in + String.concatWith ", " strList + end end