From 224226fea819795b199e0e7a28c70ce18ca94a54 Mon Sep 17 00:00:00 2001 From: humzashahid Date: Thu, 14 Mar 2024 09:38:37 +0000 Subject: [PATCH] add toString function in ROPE signature defined in rope.sml --- rope.sml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/rope.sml b/rope.sml index 0a2fc12..ae95c8a 100644 --- a/rope.sml +++ b/rope.sml @@ -5,6 +5,7 @@ sig val fromString: string -> t val foldr: ('a * string * int vector -> 'a) * 'a * t -> 'a val insert: int * string * t -> t + val toString: t -> string (* This below function verifies that line metadata is as expected, * raising an exception if it is different, @@ -291,7 +292,7 @@ struct val total = oldLen + newLen val newStrLen = String.size newStr in - Vector.tabulate (total, (fn (idx) => + Vector.tabulate (total, (fn idx => if idx < newLen then Vector.sub (newVec, idx) else Vector.sub (oldVec, idx - newLen) + newStrLen)) end @@ -303,7 +304,7 @@ struct val total = oldLen + newLen val oldStrLen = String.size oldStr in - Vector.tabulate (total, (fn (idx) => + Vector.tabulate (total, (fn idx => if idx < oldLen then Vector.sub (oldVec, idx) else Vector.sub (newVec, idx - oldLen) + oldStrLen)) end @@ -493,15 +494,18 @@ struct insLeaf (curIdx, newStr, newVec, rope, oldStr, oldVec) | _ => raise AuxConstructor + fun endInsert (rope, action) = + case action of + NoAction => rope + | AddedNode => insRoot rope + | DeletedNode => delRoot rope + fun insert (index, str, rope) = let val newVec = countLineBreaks str val (rope, action) = ins (index, str, newVec, rope) in - (case action of - NoAction => rope - | AddedNode => insRoot rope - | DeletedNode => delRoot rope) + endInsert (rope, action) end fun verifyLines rope =