verified through testing that insertion works as expected as far as contents of string is concerned. However, have added print statements which I need to remove when I have a fully working implementation
This commit is contained in:
@@ -45,7 +45,7 @@ struct
|
||||
val vecLimit = 32
|
||||
|
||||
val empty =
|
||||
{idx = 0, left = [], right = [], line = 0, leftLines = [], rightLines = []}
|
||||
{idx = 0, leftStrings = [], rightStrings = [], line = 0, leftLines = [], rightLines = []}
|
||||
|
||||
local
|
||||
fun helpToString (acc, input) =
|
||||
@@ -107,6 +107,7 @@ struct
|
||||
if isInLimit (strHd, newString, lineHd, newLines) then
|
||||
(* Fits in limit, so we can add to existing string/line vector.*)
|
||||
let
|
||||
val _ = print "line 110\n"
|
||||
val newIdx = curIdx + String.size newString
|
||||
val newStrHd = strHd ^ newString
|
||||
val newLeftString = newStrHd :: strTl
|
||||
@@ -125,13 +126,16 @@ struct
|
||||
in
|
||||
{ idx = newIdx
|
||||
, line = newLine
|
||||
, leftStrings = leftStrings
|
||||
, leftStrings = newLeftString
|
||||
, leftLines = newLeftLines
|
||||
, rightStrings = rightStrings
|
||||
, rightLines = rightLines
|
||||
}
|
||||
end
|
||||
else
|
||||
let
|
||||
val _ = print "line 137\n"
|
||||
in
|
||||
(* Does not fit in limit, so cons instead.*)
|
||||
{ idx = curIdx + String.size newString
|
||||
, line = curLine + Vector.length newLines
|
||||
@@ -140,6 +144,7 @@ struct
|
||||
, rightStrings = rightStrings
|
||||
, rightLines = rightLines
|
||||
}
|
||||
end
|
||||
| (_, _) =>
|
||||
(*
|
||||
* Because movements between string/line lists in the gap buffer
|
||||
@@ -147,6 +152,9 @@ struct
|
||||
* also means that the other one is empty.
|
||||
* So we don't need to perform addition or consing.
|
||||
*)
|
||||
let
|
||||
val _ = print "line 156\n"
|
||||
in
|
||||
{ idx = String.size newString
|
||||
, line = Vector.length newLines
|
||||
, leftStrings = [newString]
|
||||
@@ -154,6 +162,7 @@ struct
|
||||
, rightStrings = rightStrings
|
||||
, rightLines = rightLines
|
||||
}
|
||||
end
|
||||
|
||||
fun insInLeftList
|
||||
( idx
|
||||
@@ -176,6 +185,7 @@ struct
|
||||
if isInLimit (newString, leftStringsHd, newLines, leftLinesHd) then
|
||||
let
|
||||
(* Create new vector, adjusting indices as needed. *)
|
||||
val _ = print "line 188\n"
|
||||
val joinedLines =
|
||||
Vector.tabulate
|
||||
( Vector.length newLines + Vector.length leftLinesHd
|
||||
@@ -197,13 +207,14 @@ struct
|
||||
end
|
||||
else
|
||||
(* Just cons everything; no way we can join while staying in limit. *)
|
||||
let val _ = print "line 210\n" in
|
||||
{ idx = curIdx + String.size newString
|
||||
, line = curLine + Vector.length newLines
|
||||
, leftStrings = leftStringsHd :: newString :: leftStringsTl
|
||||
, leftLines = leftLinesHd :: newLines :: leftLinesTl
|
||||
, rightStrings = rightStrings
|
||||
, rightLines = rightLines
|
||||
}
|
||||
} end
|
||||
else
|
||||
(* Need to insert in the middle of the left list. *)
|
||||
let
|
||||
@@ -219,6 +230,7 @@ struct
|
||||
then
|
||||
(* Join three strings together. *)
|
||||
let
|
||||
val _ = print "line 233\n"
|
||||
val joinedLines =
|
||||
Vector.tabulate
|
||||
( Vector.length leftLinesHd + Vector.length newLines
|
||||
@@ -249,6 +261,7 @@ struct
|
||||
(* If we can join newString/lines with sub1 while
|
||||
* staying in limit. *)
|
||||
let
|
||||
val _ = print "line 264\n"
|
||||
val newLeftLines =
|
||||
Vector.tabulate (midpoint + Vector.length newLines, fn idx =>
|
||||
if idx < midpoint then Vector.sub (leftLinesHd, idx)
|
||||
@@ -276,6 +289,7 @@ struct
|
||||
(* If we can join newString/line with sub2 while staying
|
||||
* in limit. *)
|
||||
let
|
||||
val _ = print "line 292\n"
|
||||
val newLeftLines = VectorSlice.slice (leftLinesHd, 0, SOME midpoint)
|
||||
val newLeftLines = VectorSlice.vector newLeftLines
|
||||
|
||||
@@ -302,6 +316,7 @@ struct
|
||||
else
|
||||
(* Can't join on either side while staying in limit. *)
|
||||
let
|
||||
val _ = print "line 319\n"
|
||||
val lineSub1 = VectorSlice.slice (leftLinesHd, 0, SOME midpoint)
|
||||
val lineSub1 = VectorSlice.vector lineSub1
|
||||
|
||||
@@ -352,6 +367,7 @@ struct
|
||||
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
|
||||
then
|
||||
let
|
||||
val _ = print "line 370\n"
|
||||
val prevLine = curLine - Vector.length leftLinesHd
|
||||
val newRightStringsHd = leftStringsHd ^ rightStringsHd
|
||||
val newRightLinesHd =
|
||||
@@ -455,6 +471,7 @@ struct
|
||||
if isInLimit (newString, rightStringsHd, newLines, rightLinesHd) then
|
||||
(* Allocate new string because we can do so while staying in limit. *)
|
||||
let
|
||||
val _ = print "line 474\n"
|
||||
val newRightStringsHd = rightStringsHd ^ newString
|
||||
val newRightLinesHd =
|
||||
Vector.tabulate
|
||||
@@ -478,13 +495,14 @@ struct
|
||||
else
|
||||
(* Cons newString and newLines to after-the-head,
|
||||
* because we can't join while staying in the limit.*)
|
||||
let val _ = print "line 498\n" in
|
||||
{ idx = curIdx
|
||||
, line = curLine
|
||||
, leftStrings = leftStrings
|
||||
, leftLines = leftLines
|
||||
, rightStrings = rightStringsHd :: newString :: rightStringsTl
|
||||
, rightLines = rightLinesHd :: newLines :: rightLinesTl
|
||||
}
|
||||
} end
|
||||
else
|
||||
(* Have to split rightStringsHd and rightLinesHd in the middle. *)
|
||||
let
|
||||
@@ -499,6 +517,7 @@ struct
|
||||
then
|
||||
(* Join three strings together. *)
|
||||
let
|
||||
val _ = print "line 520\n"
|
||||
val newRightStringsHd = String.concat [strSub1, newString, strSub2]
|
||||
val newRightLinesHd =
|
||||
Vector.tabulate
|
||||
@@ -530,6 +549,7 @@ struct
|
||||
* staying in limit. *)
|
||||
let
|
||||
(* strSub1 ^ newString is placed on the left list. *)
|
||||
val _ = print "line 552\n"
|
||||
val newLeftStringsHd = strSub1 ^ newString
|
||||
val newLeftLinesHd =
|
||||
Vector.tabulate (Vector.length newLines + midpoint, fn idx =>
|
||||
@@ -558,6 +578,7 @@ struct
|
||||
(* If we can join newString/line with sub2 while staying
|
||||
* in limit. *)
|
||||
let
|
||||
val _ = print "line 581\n"
|
||||
val newRightStringsHd = newString ^ strSub2
|
||||
val newRightLinesHd =
|
||||
Vector.tabulate
|
||||
@@ -584,6 +605,7 @@ struct
|
||||
else
|
||||
(* Can't join on either side while staying in limit. *)
|
||||
let
|
||||
val _ = print "line 608\n"
|
||||
val lineSub1 = VectorSlice.slice (rightLinesHd, 0, SOME midpoint)
|
||||
val lineSub1 = VectorSlice.vector lineSub1
|
||||
val lineSub2 = VectorSlice.slice (rightLinesHd, midpoint, SOME
|
||||
@@ -625,6 +647,7 @@ struct
|
||||
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
|
||||
then
|
||||
let
|
||||
val _ = print "line 650\n"
|
||||
val nextLine = curLine + Vector.length rightLinesHd
|
||||
val newLeftStringsHd = leftStringsHd ^ rightStringsHd
|
||||
val newLeftLinesHd =
|
||||
@@ -697,13 +720,14 @@ struct
|
||||
end
|
||||
| (_, _) =>
|
||||
(* Right string/line is empty. *)
|
||||
let val _ = print "line 723\n" in
|
||||
{ idx = curIdx
|
||||
, line = curLine
|
||||
, leftStrings = leftStrings
|
||||
, leftLines = leftLines
|
||||
, rightStrings = [newString]
|
||||
, rightLines = [newLines]
|
||||
}
|
||||
} end
|
||||
|
||||
fun ins
|
||||
( idx
|
||||
@@ -755,7 +779,7 @@ struct
|
||||
|
||||
fun insert (idx, newString, buffer: t) =
|
||||
let
|
||||
val newLines = countLineBreaks newString
|
||||
val newLines = Vector.fromList []
|
||||
in
|
||||
ins
|
||||
( idx
|
||||
|
||||
BIN
tests/compare
Executable file
BIN
tests/compare
Executable file
Binary file not shown.
16
tests/compare.mlb
Normal file
16
tests/compare.mlb
Normal file
@@ -0,0 +1,16 @@
|
||||
$(SML_LIB)/basis/basis.mlb
|
||||
|
||||
ann
|
||||
"allowVectorExps true"
|
||||
in
|
||||
../data-sets/svelte.sml
|
||||
(*
|
||||
../data-sets/rust.sml
|
||||
../data-sets/seph.sml
|
||||
../data-sets/automerge.sml
|
||||
*)
|
||||
end
|
||||
|
||||
../src/tiny_rope.sml
|
||||
../src/line_gap.sml
|
||||
compare_to_rope.sml
|
||||
@@ -1,16 +1,67 @@
|
||||
structure CompareToRope =
|
||||
struct
|
||||
local
|
||||
fun folder ((pos, delNum, insStr), buffer, fIns, fDel) =
|
||||
let
|
||||
val buffer =
|
||||
if String.size insStr > 0 then
|
||||
fIns (pos, insStr, buffer) else buffer
|
||||
in
|
||||
buffer
|
||||
end
|
||||
fun compareTxns arr =
|
||||
Vector.foldli
|
||||
(fn (idx, (pos, delNum, insStr), (rope, gapBuffer)) =>
|
||||
let
|
||||
val _ = print ("idx: " ^ Int.toString idx ^ "\n")
|
||||
val oldRope = rope
|
||||
val strSize = String.size insStr
|
||||
|
||||
val rope =
|
||||
if strSize > 0 then TinyRope.insert (pos, insStr, rope) else rope
|
||||
|
||||
val gapBuffer =
|
||||
if strSize > 0 then LineGap.insert (pos, insStr, gapBuffer)
|
||||
else gapBuffer
|
||||
|
||||
val ropeString = TinyRope.toString rope
|
||||
val gapBufferString = LineGap.toString gapBuffer
|
||||
in
|
||||
if ropeString = gapBufferString then
|
||||
(rope, gapBuffer)
|
||||
else
|
||||
let
|
||||
val _ = print
|
||||
("difference detected at txn number: " ^ (Int.toString idx)
|
||||
^ "\n")
|
||||
val txn = String.concat
|
||||
[ "offending txn: \n"
|
||||
, "pos: "
|
||||
, Int.toString pos
|
||||
, ", delNum: "
|
||||
, Int.toString delNum
|
||||
, ", insStr: |"
|
||||
, insStr
|
||||
, "|\n"
|
||||
]
|
||||
val _ = print txn
|
||||
|
||||
val _ = print "before offending string: \n"
|
||||
val _ = print (TinyRope.toString oldRope)
|
||||
val _ = print "\n"
|
||||
|
||||
val _ = print "rope string: \n"
|
||||
val _ = print (ropeString ^ "\n")
|
||||
val _ = print "gap string: \n"
|
||||
val _ = print (gapBufferString ^ "\n")
|
||||
val _ = raise Empty
|
||||
in
|
||||
(rope, gapBuffer)
|
||||
end
|
||||
end) (TinyRope.empty, LineGap.empty) arr
|
||||
|
||||
fun main () =
|
||||
let
|
||||
val _ = compareTxns SvelteComponent.txns
|
||||
(*
|
||||
val _ = compareTxns Rust.txns
|
||||
val _ = compareTxns Seph.txns
|
||||
val _ = compareTxns Automerge.txns
|
||||
*)
|
||||
in
|
||||
fun runTxns () =
|
||||
Vector.foldl folder Txn.empty Txn.txns
|
||||
()
|
||||
end
|
||||
|
||||
val _ = main ()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user