add function to verify line metadata in rope.sml
This commit is contained in:
1
proj.mlb
1
proj.mlb
@@ -10,4 +10,5 @@ in
|
|||||||
end
|
end
|
||||||
|
|
||||||
tiny_rope.sml
|
tiny_rope.sml
|
||||||
|
rope.sml
|
||||||
utils.sml
|
utils.sml
|
||||||
|
|||||||
18
rope.sml
18
rope.sml
@@ -5,6 +5,11 @@ sig
|
|||||||
val fromString: string -> t
|
val fromString: string -> t
|
||||||
val foldr: ('a * string * int vector -> 'a) * 'a * t -> 'a
|
val foldr: ('a * string * int vector -> 'a) * 'a * t -> 'a
|
||||||
val insert: int * string * t -> t
|
val insert: int * string * t -> t
|
||||||
|
|
||||||
|
(* This below function verifies that line metadata is as expected,
|
||||||
|
* raising an exception if it is different,
|
||||||
|
* and returning true if it is the same. *)
|
||||||
|
val verifyLines: t -> bool
|
||||||
end
|
end
|
||||||
|
|
||||||
structure Rope :> ROPE =
|
structure Rope :> ROPE =
|
||||||
@@ -438,7 +443,6 @@ struct
|
|||||||
(node, DeletedNode)
|
(node, DeletedNode)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
fun ins (curIdx, newStr, newVec, rope) =
|
fun ins (curIdx, newStr, newVec, rope) =
|
||||||
case rope of
|
case rope of
|
||||||
N2 (l, lms, lmv, r) =>
|
N2 (l, lms, lmv, r) =>
|
||||||
@@ -500,4 +504,16 @@ struct
|
|||||||
| DeletedNode => delRoot rope)
|
| DeletedNode => delRoot rope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun verifyLines rope =
|
||||||
|
foldr
|
||||||
|
( (fn (_, str, vec) =>
|
||||||
|
let
|
||||||
|
val strVec = countLineBreaks str
|
||||||
|
val isSame = strVec = vec
|
||||||
|
in
|
||||||
|
if isSame then true else raise Empty
|
||||||
|
end)
|
||||||
|
, true
|
||||||
|
, rope
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user