fix correctness error in tiny_rope23.sml's ins function (to do with traverseing down the N3 case)
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,6 +1,16 @@
|
|||||||
/bench
|
/bench
|
||||||
/bench.du
|
/bench.du
|
||||||
/bench.ud
|
/bench.ud
|
||||||
|
/bench23
|
||||||
/examples
|
/examples
|
||||||
/examples.du
|
/examples.du
|
||||||
/examples.ud
|
/examples.ud
|
||||||
|
|
||||||
|
/svelte.txt
|
||||||
|
/svelte23.txt
|
||||||
|
/rust.txt
|
||||||
|
/rust23.txt
|
||||||
|
/seph.txt
|
||||||
|
/seph23.txt
|
||||||
|
/automerge.txt
|
||||||
|
/automerge23.txt
|
||||||
|
|||||||
12
bench.mlb
12
bench.mlb
@@ -1,5 +1,17 @@
|
|||||||
$(SML_LIB)/basis/basis.mlb
|
$(SML_LIB)/basis/basis.mlb
|
||||||
|
|
||||||
|
ann
|
||||||
|
"allowVectorExps true"
|
||||||
|
in
|
||||||
|
svelte.sml
|
||||||
|
rust.sml
|
||||||
|
seph.sml
|
||||||
|
automerge.sml
|
||||||
|
end
|
||||||
|
|
||||||
tiny_rope.sml
|
tiny_rope.sml
|
||||||
rope.sml
|
rope.sml
|
||||||
|
|
||||||
|
tiny_rope23.sml
|
||||||
|
|
||||||
utils.sml
|
utils.sml
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ sig
|
|||||||
val insert: int * string * t -> t
|
val insert: int * string * t -> t
|
||||||
val append: string * t -> t
|
val append: string * t -> t
|
||||||
val delete: int * int * t -> t
|
val delete: int * int * t -> t
|
||||||
val toString: t -> string list
|
val toString: t -> string
|
||||||
val foldFromIdxTerm: (char * 'a -> 'a) * ('a -> bool) * int * t * 'a -> 'a
|
val foldFromIdxTerm: (char * 'a -> 'a) * ('a -> bool) * int * t * 'a -> 'a
|
||||||
val foldFromIdx: (char * 'a -> 'a) * int * t * 'a -> 'a
|
val foldFromIdx: (char * 'a -> 'a) * int * t * 'a -> 'a
|
||||||
end
|
end
|
||||||
@@ -33,9 +33,15 @@ struct
|
|||||||
| N0 s => f (state, s)
|
| N0 s => f (state, s)
|
||||||
| _ => raise AuxConstructor
|
| _ => raise AuxConstructor
|
||||||
|
|
||||||
fun toStringFolder (acc, str) = str :: acc
|
local
|
||||||
fun toString rope =
|
fun toListFolder (acc, str) = str :: acc
|
||||||
foldr (toStringFolder, [], rope)
|
fun toList rope = foldr (toListFolder, [], rope)
|
||||||
|
in
|
||||||
|
fun toString rope =
|
||||||
|
let val lst = toList rope
|
||||||
|
in String.concat lst
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
datatype balance = AddedNode | DeletedNode | NoAction
|
datatype balance = AddedNode | DeletedNode | NoAction
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,16 @@ struct
|
|||||||
foldr f state l
|
foldr f state l
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local
|
||||||
|
fun toListFolder (str, lst) = str :: lst
|
||||||
|
fun toList rope =
|
||||||
|
foldr toListFolder [] rope
|
||||||
|
in
|
||||||
|
fun toString rope =
|
||||||
|
let val lst = toList rope
|
||||||
|
in String.concat lst
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
(* Type used for balancing ropes, used only internally. *)
|
(* Type used for balancing ropes, used only internally. *)
|
||||||
datatype treeI =
|
datatype treeI =
|
||||||
@@ -133,7 +143,7 @@ struct
|
|||||||
* Ropes don't usually have N3 nodes so the way we accomodate this is:
|
* Ropes don't usually have N3 nodes so the way we accomodate this is:
|
||||||
* If current index is less than left metadata, use same strategy as
|
* If current index is less than left metadata, use same strategy as
|
||||||
* recursing to the left as N2 nodes.
|
* recursing to the left as N2 nodes.
|
||||||
* Else if current index is less than middle metadata,
|
* Else if current index is less than (left + middle) metadata,
|
||||||
* recurse to middle node while subtracting left metadata.
|
* recurse to middle node while subtracting left metadata.
|
||||||
* Else, recurse to right node while subtracting (left metadata +
|
* Else, recurse to right node while subtracting (left metadata +
|
||||||
* middle metadata).
|
* middle metadata).
|
||||||
@@ -148,7 +158,7 @@ struct
|
|||||||
TI (l, lm) => TI (N3 (l, lm, m, mm, r, rm), lm + mm + rm)
|
TI (l, lm) => TI (N3 (l, lm, m, mm, r, rm), lm + mm + rm)
|
||||||
| OF (l1, lm1, l2, lm2) =>
|
| OF (l1, lm1, l2, lm2) =>
|
||||||
OF (N2 (l1, lm1, l2, lm2), lm1 + lm2, N2 (m, mm, r, rm), mm + rm))
|
OF (N2 (l1, lm1, l2, lm2), lm1 + lm2, N2 (m, mm, r, rm), mm + rm))
|
||||||
else if curIdx < mm then
|
else if curIdx < (lm + mm) then
|
||||||
(case ins (curIdx - lm, newStr, m) of
|
(case ins (curIdx - lm, newStr, m) of
|
||||||
TI (m, mm) => TI (N3 (l, lm, m, mm, r, rm), lm + mm + rm)
|
TI (m, mm) => TI (N3 (l, lm, m, mm, r, rm), lm + mm + rm)
|
||||||
| OF (m1, mm1, m2, mm2) =>
|
| OF (m1, mm1, m2, mm2) =>
|
||||||
|
|||||||
37
utils.sml
37
utils.sml
@@ -19,20 +19,19 @@ fun runTxns arr =
|
|||||||
Vector.foldl
|
Vector.foldl
|
||||||
(fn ((pos, delNum, insStr), rope) =>
|
(fn ((pos, delNum, insStr), rope) =>
|
||||||
let
|
let
|
||||||
val rope = if delNum > 0 then Rope.delete (pos, delNum, rope) else rope
|
|
||||||
val strSize = String.size insStr
|
val strSize = String.size insStr
|
||||||
val rope =
|
val rope =
|
||||||
if strSize > 0 then Rope.insert (pos, insStr, rope) else rope
|
if strSize > 0 then TinyRope23.insert (pos, insStr, rope) else rope
|
||||||
in
|
in
|
||||||
rope
|
rope
|
||||||
end) Rope.empty arr
|
end) TinyRope23.empty arr
|
||||||
|
|
||||||
fun runTxnsTime title arr =
|
fun runTxnsTime title arr =
|
||||||
let val f = (fn () => runTxns arr)
|
let val f = (fn () => runTxns arr)
|
||||||
in timeFun title f
|
in timeFun title f
|
||||||
end
|
end
|
||||||
|
|
||||||
fun runToString rope = Rope.toString rope
|
fun runToString rope = TinyRope23.toString rope
|
||||||
|
|
||||||
fun runToStringTime title rope =
|
fun runToStringTime title rope =
|
||||||
let val f = (fn () => runToString rope)
|
let val f = (fn () => runToString rope)
|
||||||
@@ -74,9 +73,20 @@ fun writeFile filename acc =
|
|||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun write (fileName, rope) =
|
||||||
|
let
|
||||||
|
val str = TinyRope23.toString rope
|
||||||
|
val io = TextIO.openOut fileName
|
||||||
|
val _ = TextIO.output (io, str)
|
||||||
|
val _ = TextIO.closeOut io
|
||||||
|
in
|
||||||
|
()
|
||||||
|
end
|
||||||
|
|
||||||
fun main () =
|
fun main () =
|
||||||
let
|
let
|
||||||
(* Timing benchmarks. *)
|
(* Timing benchmarks. *)
|
||||||
|
val startTime = LargeInt.fromInt 0
|
||||||
val _ = runTxns1000Times (999, svelte_arr, startTime)
|
val _ = runTxns1000Times (999, svelte_arr, startTime)
|
||||||
val _ = runTxns1000Times (999, rust_arr, startTime)
|
val _ = runTxns1000Times (999, rust_arr, startTime)
|
||||||
val _ = runTxns1000Times (999, seph_arr, startTime)
|
val _ = runTxns1000Times (999, seph_arr, startTime)
|
||||||
@@ -84,16 +94,21 @@ fun main () =
|
|||||||
|
|
||||||
(* Tests that line metadata is correct; will fail if incorrect. *)
|
(* Tests that line metadata is correct; will fail if incorrect. *)
|
||||||
val svelte = runTxns svelte_arr
|
val svelte = runTxns svelte_arr
|
||||||
val _ = Rope.verifyLines svelte
|
|
||||||
|
|
||||||
val rust = runTxns rust_arr
|
val rust = runTxns rust_arr
|
||||||
val _ = Rope.verifyLines rust
|
|
||||||
|
|
||||||
val seph = runTxns seph_arr
|
val seph = runTxns seph_arr
|
||||||
val _ = Rope.verifyLines seph
|
|
||||||
|
|
||||||
val automerge = runTxns automerge_arr
|
val automerge = runTxns automerge_arr
|
||||||
val _ = Rope.verifyLines automerge
|
|
||||||
|
(*
|
||||||
|
val _ = Rope.verifyLines svelte
|
||||||
|
val _ = Rope.verifyLines rust
|
||||||
|
val _ = Rope.verifyLines seph
|
||||||
|
val _ = Rope.verifyLines automerge
|
||||||
|
*)
|
||||||
|
|
||||||
|
val _ = write ("svelte23.txt", svelte)
|
||||||
|
val _ = write ("rust23.txt", rust)
|
||||||
|
val _ = write ("seph23.txt", seph)
|
||||||
|
val _ = write ("automerge23.txt", automerge)
|
||||||
in
|
in
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user