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 vecLimit = 32
|
||||||
|
|
||||||
val empty =
|
val empty =
|
||||||
{idx = 0, left = [], right = [], line = 0, leftLines = [], rightLines = []}
|
{idx = 0, leftStrings = [], rightStrings = [], line = 0, leftLines = [], rightLines = []}
|
||||||
|
|
||||||
local
|
local
|
||||||
fun helpToString (acc, input) =
|
fun helpToString (acc, input) =
|
||||||
@@ -107,6 +107,7 @@ struct
|
|||||||
if isInLimit (strHd, newString, lineHd, newLines) then
|
if isInLimit (strHd, newString, lineHd, newLines) then
|
||||||
(* Fits in limit, so we can add to existing string/line vector.*)
|
(* Fits in limit, so we can add to existing string/line vector.*)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 110\n"
|
||||||
val newIdx = curIdx + String.size newString
|
val newIdx = curIdx + String.size newString
|
||||||
val newStrHd = strHd ^ newString
|
val newStrHd = strHd ^ newString
|
||||||
val newLeftString = newStrHd :: strTl
|
val newLeftString = newStrHd :: strTl
|
||||||
@@ -125,13 +126,16 @@ struct
|
|||||||
in
|
in
|
||||||
{ idx = newIdx
|
{ idx = newIdx
|
||||||
, line = newLine
|
, line = newLine
|
||||||
, leftStrings = leftStrings
|
, leftStrings = newLeftString
|
||||||
, leftLines = newLeftLines
|
, leftLines = newLeftLines
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
, rightLines = rightLines
|
, rightLines = rightLines
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
let
|
||||||
|
val _ = print "line 137\n"
|
||||||
|
in
|
||||||
(* Does not fit in limit, so cons instead.*)
|
(* Does not fit in limit, so cons instead.*)
|
||||||
{ idx = curIdx + String.size newString
|
{ idx = curIdx + String.size newString
|
||||||
, line = curLine + Vector.length newLines
|
, line = curLine + Vector.length newLines
|
||||||
@@ -140,6 +144,7 @@ struct
|
|||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
, rightLines = rightLines
|
, rightLines = rightLines
|
||||||
}
|
}
|
||||||
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(*
|
(*
|
||||||
* Because movements between string/line lists in the gap buffer
|
* Because movements between string/line lists in the gap buffer
|
||||||
@@ -147,6 +152,9 @@ struct
|
|||||||
* also means that the other one is empty.
|
* also means that the other one is empty.
|
||||||
* So we don't need to perform addition or consing.
|
* So we don't need to perform addition or consing.
|
||||||
*)
|
*)
|
||||||
|
let
|
||||||
|
val _ = print "line 156\n"
|
||||||
|
in
|
||||||
{ idx = String.size newString
|
{ idx = String.size newString
|
||||||
, line = Vector.length newLines
|
, line = Vector.length newLines
|
||||||
, leftStrings = [newString]
|
, leftStrings = [newString]
|
||||||
@@ -154,6 +162,7 @@ struct
|
|||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
, rightLines = rightLines
|
, rightLines = rightLines
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
fun insInLeftList
|
fun insInLeftList
|
||||||
( idx
|
( idx
|
||||||
@@ -176,6 +185,7 @@ struct
|
|||||||
if isInLimit (newString, leftStringsHd, newLines, leftLinesHd) then
|
if isInLimit (newString, leftStringsHd, newLines, leftLinesHd) then
|
||||||
let
|
let
|
||||||
(* Create new vector, adjusting indices as needed. *)
|
(* Create new vector, adjusting indices as needed. *)
|
||||||
|
val _ = print "line 188\n"
|
||||||
val joinedLines =
|
val joinedLines =
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
( Vector.length newLines + Vector.length leftLinesHd
|
( Vector.length newLines + Vector.length leftLinesHd
|
||||||
@@ -197,13 +207,14 @@ struct
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
(* Just cons everything; no way we can join while staying in limit. *)
|
(* Just cons everything; no way we can join while staying in limit. *)
|
||||||
|
let val _ = print "line 210\n" in
|
||||||
{ idx = curIdx + String.size newString
|
{ idx = curIdx + String.size newString
|
||||||
, line = curLine + Vector.length newLines
|
, line = curLine + Vector.length newLines
|
||||||
, leftStrings = leftStringsHd :: newString :: leftStringsTl
|
, leftStrings = leftStringsHd :: newString :: leftStringsTl
|
||||||
, leftLines = leftLinesHd :: newLines :: leftLinesTl
|
, leftLines = leftLinesHd :: newLines :: leftLinesTl
|
||||||
, rightStrings = rightStrings
|
, rightStrings = rightStrings
|
||||||
, rightLines = rightLines
|
, rightLines = rightLines
|
||||||
}
|
} end
|
||||||
else
|
else
|
||||||
(* Need to insert in the middle of the left list. *)
|
(* Need to insert in the middle of the left list. *)
|
||||||
let
|
let
|
||||||
@@ -219,6 +230,7 @@ struct
|
|||||||
then
|
then
|
||||||
(* Join three strings together. *)
|
(* Join three strings together. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 233\n"
|
||||||
val joinedLines =
|
val joinedLines =
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
( Vector.length leftLinesHd + Vector.length newLines
|
( Vector.length leftLinesHd + Vector.length newLines
|
||||||
@@ -249,6 +261,7 @@ struct
|
|||||||
(* If we can join newString/lines with sub1 while
|
(* If we can join newString/lines with sub1 while
|
||||||
* staying in limit. *)
|
* staying in limit. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 264\n"
|
||||||
val newLeftLines =
|
val newLeftLines =
|
||||||
Vector.tabulate (midpoint + Vector.length newLines, fn idx =>
|
Vector.tabulate (midpoint + Vector.length newLines, fn idx =>
|
||||||
if idx < midpoint then Vector.sub (leftLinesHd, idx)
|
if idx < midpoint then Vector.sub (leftLinesHd, idx)
|
||||||
@@ -276,6 +289,7 @@ struct
|
|||||||
(* If we can join newString/line with sub2 while staying
|
(* If we can join newString/line with sub2 while staying
|
||||||
* in limit. *)
|
* in limit. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 292\n"
|
||||||
val newLeftLines = VectorSlice.slice (leftLinesHd, 0, SOME midpoint)
|
val newLeftLines = VectorSlice.slice (leftLinesHd, 0, SOME midpoint)
|
||||||
val newLeftLines = VectorSlice.vector newLeftLines
|
val newLeftLines = VectorSlice.vector newLeftLines
|
||||||
|
|
||||||
@@ -302,6 +316,7 @@ struct
|
|||||||
else
|
else
|
||||||
(* Can't join on either side while staying in limit. *)
|
(* Can't join on either side while staying in limit. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 319\n"
|
||||||
val lineSub1 = VectorSlice.slice (leftLinesHd, 0, SOME midpoint)
|
val lineSub1 = VectorSlice.slice (leftLinesHd, 0, SOME midpoint)
|
||||||
val lineSub1 = VectorSlice.vector lineSub1
|
val lineSub1 = VectorSlice.vector lineSub1
|
||||||
|
|
||||||
@@ -352,6 +367,7 @@ struct
|
|||||||
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
|
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
|
||||||
then
|
then
|
||||||
let
|
let
|
||||||
|
val _ = print "line 370\n"
|
||||||
val prevLine = curLine - Vector.length leftLinesHd
|
val prevLine = curLine - Vector.length leftLinesHd
|
||||||
val newRightStringsHd = leftStringsHd ^ rightStringsHd
|
val newRightStringsHd = leftStringsHd ^ rightStringsHd
|
||||||
val newRightLinesHd =
|
val newRightLinesHd =
|
||||||
@@ -455,6 +471,7 @@ struct
|
|||||||
if isInLimit (newString, rightStringsHd, newLines, rightLinesHd) then
|
if isInLimit (newString, rightStringsHd, newLines, rightLinesHd) then
|
||||||
(* Allocate new string because we can do so while staying in limit. *)
|
(* Allocate new string because we can do so while staying in limit. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 474\n"
|
||||||
val newRightStringsHd = rightStringsHd ^ newString
|
val newRightStringsHd = rightStringsHd ^ newString
|
||||||
val newRightLinesHd =
|
val newRightLinesHd =
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
@@ -478,13 +495,14 @@ struct
|
|||||||
else
|
else
|
||||||
(* Cons newString and newLines to after-the-head,
|
(* Cons newString and newLines to after-the-head,
|
||||||
* because we can't join while staying in the limit.*)
|
* because we can't join while staying in the limit.*)
|
||||||
|
let val _ = print "line 498\n" in
|
||||||
{ idx = curIdx
|
{ idx = curIdx
|
||||||
, line = curLine
|
, line = curLine
|
||||||
, leftStrings = leftStrings
|
, leftStrings = leftStrings
|
||||||
, leftLines = leftLines
|
, leftLines = leftLines
|
||||||
, rightStrings = rightStringsHd :: newString :: rightStringsTl
|
, rightStrings = rightStringsHd :: newString :: rightStringsTl
|
||||||
, rightLines = rightLinesHd :: newLines :: rightLinesTl
|
, rightLines = rightLinesHd :: newLines :: rightLinesTl
|
||||||
}
|
} end
|
||||||
else
|
else
|
||||||
(* Have to split rightStringsHd and rightLinesHd in the middle. *)
|
(* Have to split rightStringsHd and rightLinesHd in the middle. *)
|
||||||
let
|
let
|
||||||
@@ -499,6 +517,7 @@ struct
|
|||||||
then
|
then
|
||||||
(* Join three strings together. *)
|
(* Join three strings together. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 520\n"
|
||||||
val newRightStringsHd = String.concat [strSub1, newString, strSub2]
|
val newRightStringsHd = String.concat [strSub1, newString, strSub2]
|
||||||
val newRightLinesHd =
|
val newRightLinesHd =
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
@@ -530,6 +549,7 @@ struct
|
|||||||
* staying in limit. *)
|
* staying in limit. *)
|
||||||
let
|
let
|
||||||
(* strSub1 ^ newString is placed on the left list. *)
|
(* strSub1 ^ newString is placed on the left list. *)
|
||||||
|
val _ = print "line 552\n"
|
||||||
val newLeftStringsHd = strSub1 ^ newString
|
val newLeftStringsHd = strSub1 ^ newString
|
||||||
val newLeftLinesHd =
|
val newLeftLinesHd =
|
||||||
Vector.tabulate (Vector.length newLines + midpoint, fn idx =>
|
Vector.tabulate (Vector.length newLines + midpoint, fn idx =>
|
||||||
@@ -558,6 +578,7 @@ struct
|
|||||||
(* If we can join newString/line with sub2 while staying
|
(* If we can join newString/line with sub2 while staying
|
||||||
* in limit. *)
|
* in limit. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 581\n"
|
||||||
val newRightStringsHd = newString ^ strSub2
|
val newRightStringsHd = newString ^ strSub2
|
||||||
val newRightLinesHd =
|
val newRightLinesHd =
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
@@ -584,6 +605,7 @@ struct
|
|||||||
else
|
else
|
||||||
(* Can't join on either side while staying in limit. *)
|
(* Can't join on either side while staying in limit. *)
|
||||||
let
|
let
|
||||||
|
val _ = print "line 608\n"
|
||||||
val lineSub1 = VectorSlice.slice (rightLinesHd, 0, SOME midpoint)
|
val lineSub1 = VectorSlice.slice (rightLinesHd, 0, SOME midpoint)
|
||||||
val lineSub1 = VectorSlice.vector lineSub1
|
val lineSub1 = VectorSlice.vector lineSub1
|
||||||
val lineSub2 = VectorSlice.slice (rightLinesHd, midpoint, SOME
|
val lineSub2 = VectorSlice.slice (rightLinesHd, midpoint, SOME
|
||||||
@@ -625,6 +647,7 @@ struct
|
|||||||
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
|
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
|
||||||
then
|
then
|
||||||
let
|
let
|
||||||
|
val _ = print "line 650\n"
|
||||||
val nextLine = curLine + Vector.length rightLinesHd
|
val nextLine = curLine + Vector.length rightLinesHd
|
||||||
val newLeftStringsHd = leftStringsHd ^ rightStringsHd
|
val newLeftStringsHd = leftStringsHd ^ rightStringsHd
|
||||||
val newLeftLinesHd =
|
val newLeftLinesHd =
|
||||||
@@ -697,13 +720,14 @@ struct
|
|||||||
end
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* Right string/line is empty. *)
|
(* Right string/line is empty. *)
|
||||||
|
let val _ = print "line 723\n" in
|
||||||
{ idx = curIdx
|
{ idx = curIdx
|
||||||
, line = curLine
|
, line = curLine
|
||||||
, leftStrings = leftStrings
|
, leftStrings = leftStrings
|
||||||
, leftLines = leftLines
|
, leftLines = leftLines
|
||||||
, rightStrings = [newString]
|
, rightStrings = [newString]
|
||||||
, rightLines = [newLines]
|
, rightLines = [newLines]
|
||||||
}
|
} end
|
||||||
|
|
||||||
fun ins
|
fun ins
|
||||||
( idx
|
( idx
|
||||||
@@ -755,7 +779,7 @@ struct
|
|||||||
|
|
||||||
fun insert (idx, newString, buffer: t) =
|
fun insert (idx, newString, buffer: t) =
|
||||||
let
|
let
|
||||||
val newLines = countLineBreaks newString
|
val newLines = Vector.fromList []
|
||||||
in
|
in
|
||||||
ins
|
ins
|
||||||
( idx
|
( 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 =
|
structure CompareToRope =
|
||||||
struct
|
struct
|
||||||
local
|
fun compareTxns arr =
|
||||||
fun folder ((pos, delNum, insStr), buffer, fIns, fDel) =
|
Vector.foldli
|
||||||
let
|
(fn (idx, (pos, delNum, insStr), (rope, gapBuffer)) =>
|
||||||
val buffer =
|
let
|
||||||
if String.size insStr > 0 then
|
val _ = print ("idx: " ^ Int.toString idx ^ "\n")
|
||||||
fIns (pos, insStr, buffer) else buffer
|
val oldRope = rope
|
||||||
in
|
val strSize = String.size insStr
|
||||||
buffer
|
|
||||||
end
|
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
|
in
|
||||||
fun runTxns () =
|
()
|
||||||
Vector.foldl folder Txn.empty Txn.txns
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
val _ = main ()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user