@@ -45,7 +45,7 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
4545 * @param orig The original sequence.
4646 * @param rev The revised sequence.
4747 * @return A minimum [PathNode] across the differences graph.
48- * @throws DifferentiationFailedException if a diff path could not be found.
48+ * @throws IllegalStateException if a diff path could not be found.
4949 */
5050 private fun buildPath (orig : List <T >, rev : List <T >, progress : DiffAlgorithmListener ? ): PathNode ? {
5151 // these are local constants
@@ -74,13 +74,13 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
7474 }
7575 diagonal[kminus] = null // no longer used
7676 var j = i - k
77- var node = PathNode (i, j, false , false , prev)
77+ var node = PathNode (i, j, snake = false , bootstrap = false , prev = prev)
7878 while (i < N && j < M && equalizer.invoke(orig[i], rev[j])) {
7979 i++
8080 j++
8181 }
8282 if (i != node.i) {
83- node = PathNode (i, j, true , false , node)
83+ node = PathNode (i, j, snake = true , bootstrap = false , prev = node)
8484 }
8585 diagonal[kmiddle] = node
8686 if (i >= N && j >= M ) {
@@ -94,14 +94,13 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
9494 }
9595
9696 /* *
97- * Constructs a [Patch] from a difference path.
97+ * Constructs a patch from a difference path.
9898 *
9999 * @param actualPath The path.
100100 * @param orig The original sequence.
101101 * @param rev The revised sequence.
102- * @return A [Patch] script corresponding to the path.
103- * @throws DifferentiationFailedException if a [Patch] could not be built from the given
104- * path.
102+ * @return A list of [Change]s corresponding to the path.
103+ * @throws IllegalStateException if a patch could not be built from the given path.
105104 */
106105 private fun buildRevision (actualPath : PathNode ? , orig : List <T >, rev : List <T >): List <Change > {
107106 var path: PathNode ? = actualPath
@@ -114,14 +113,14 @@ internal class MyersDiff<T>(private val equalizer: (T, T) -> Boolean = { t1, t2
114113 val i: Int = path.i
115114 val j: Int = path.j
116115 path = path.prev
117- val ianchor : Int = path!! .i
118- val janchor : Int = path.j
119- if (ianchor == i && janchor != j) {
120- changes.add(Change (DeltaType .INSERT , ianchor , i, janchor , j))
121- } else if (ianchor != i && janchor == j) {
122- changes.add(Change (DeltaType .DELETE , ianchor , i, janchor , j))
116+ val iAnchor : Int = path!! .i
117+ val jAnchor : Int = path.j
118+ if (iAnchor == i && jAnchor != j) {
119+ changes.add(Change (DeltaType .INSERT , iAnchor , i, jAnchor , j))
120+ } else if (iAnchor != i && jAnchor == j) {
121+ changes.add(Change (DeltaType .DELETE , iAnchor , i, jAnchor , j))
123122 } else {
124- changes.add(Change (DeltaType .CHANGE , ianchor , i, janchor , j))
123+ changes.add(Change (DeltaType .CHANGE , iAnchor , i, jAnchor , j))
125124 }
126125 if (path.snake) {
127126 path = path.prev
0 commit comments