List.myers_difference
myers_difference
, go back to List module for more information.
Specs
Returns a keyword list that represents an edit script.
The algorithm is outlined in the "An O(ND) Difference Algorithm and Its Variations" paper by E. Myers.
An edit script is a keyword list. Each key describes the "editing action" to
take in order to bring list1
closer to being equal to list2
; a key can be
:eq
, :ins
, or :del
. Each value is a sublist of either list1
or list2
that should be inserted (if the corresponding key :ins
), deleted (if the
corresponding key is :del
), or left alone (if the corresponding key is
:eq
) in list1
in order to be closer to list2
.
See myers_difference/3
if you want to handle nesting in the diff scripts.
Examples
iex> List.myers_difference([1, 4, 2, 3], [1, 2, 3, 4])
[eq: [1], del: [4], eq: [2, 3], ins: [4]]
Specs
myers_difference(list(), list(), (term(), term() -> script | nil)) :: script when script: [{:eq | :ins | :del | :diff, list()}]
Returns a keyword list that represents an edit script with nested diffs.
This is an extension of myers_difference/2
where a diff_script
function
can be given in case it is desired to compute nested differences. The function
may return a list with the inner edit script or nil
in case there is no
such script. The returned inner edit script will be under the :diff
key.
Examples
iex> List.myers_difference(["a", "db", "c"], ["a", "bc"], &String.myers_difference/2)
[eq: ["a"], diff: [del: "d", eq: "b", ins: "c"], del: ["c"]]