add to_string function

This commit is contained in:
Humza Shahid
2023-11-13 09:03:29 +00:00
parent 6cd3db9104
commit 137fe24ef5
6 changed files with 2916 additions and 2672 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
proj
proj.du
proj.ud

BIN
proj

Binary file not shown.

1934
proj.du

File diff suppressed because it is too large Load Diff

3590
proj.ud

File diff suppressed because it is too large Load Diff

View File

@@ -13,6 +13,7 @@ exception Size
exception Ins
exception Substring
exception Delete
exception To_string
fun size rope =
case rope of
@@ -374,3 +375,24 @@ fun delete start length rope =
in
t
end
fun to_str acc rope =
case rope of
N0 str =>
(str::acc)
| N1 t =>
to_str acc t
| N2 (l, _, _, r) =>
let
val acc = to_str acc r
in
to_str acc l
end
| _ => raise To_string
fun to_string rope =
let
val lst = to_str [] rope
in
String.concat lst
end

View File

@@ -3,13 +3,13 @@ fun time_func title f =
val title = String.concat ["Starting " , title , "..."]
val _ = (print title)
val start_time = Time.now()
val start_time = Time.toMilliseconds start_time
val start_time = Time.toNanoseconds start_time
val x = f()
val end_time = Time.now()
val end_time = Time.toMilliseconds end_time
val end_time = Time.toNanoseconds end_time
val time_diff = end_time - start_time
val time_diff = LargeInt.toString time_diff
val time_took = String.concat ["took", time_diff, " ms\n"]
val time_took = String.concat ["took ", time_diff, " nanoseconds\n"]
val _ = (print time_took)
in
x
@@ -19,9 +19,15 @@ fun run_txns arr =
Vector.foldl
(fn ((pos, del_num, ins_str), rope) =>
let
val rope = if del_num > 0 then delete pos del_num rope else rope
val rope =
if del_num > 0
then delete pos del_num rope
else rope
val str_size = String.size ins_str
val rope = if str_size > 0 then insert pos ins_str rope else rope
val rope =
if str_size > 0
then insert pos ins_str rope
else rope
in
rope
end)
@@ -34,12 +40,27 @@ fun run_txns_time title arr =
time_func title f
end
fun run_to_string rope =
to_string rope
fun run_to_string_time title rope =
let
val f = (fn () => run_to_string rope)
in
time_func title f
end
val _ =
let
val _ = run_txns_time "svelte" svelte_arr
val _ = run_txns_time "rust" rust_arr
val _ = run_txns_time "seph" seph_arr
val _ = run_txns_time "automerge" automerge_arr
val svelte = run_txns_time "svelte" svelte_arr
val rust = run_txns_time "rust" rust_arr
val seph = run_txns_time "seph" seph_arr
val automerge = run_txns_time "automerge" automerge_arr
val _ = run_to_string_time "svelte to_string" svelte
val _ = run_to_string_time "rust to_string" rust
val _ = run_to_string_time "seph to_string" seph
val _ = run_to_string_time "automerge to_string" automerge
in
()
end