You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By "complex" data structures we mean arrays within arrays and hashes
within arrays (and everything under the sun inside of them).
In order to diff a complex array, we need to have the ability to show a
diff that reaches into inner arrays or hashes and shows the diff for
them too. That is, we need to compare each item in the array, and if we
have two elements which are different, and they are themselves arrays or
hashes, we need to descend into them and diff each of their elements
as well.
We can already diff two complex hashes in this manner because we have
custom diffing logic for hashes, where an added key is treated as an
insert, a missing key is treated as a delete, and a changed key is
treated as a delete + an insert. To show a diff for two hashes, we
merely go back over the diff information and look for a delete followed
by an insert, treating it as a change, and if the changed value is an
array or hash we know to descend.
However, this approach does not work for arrays because we are using the
patience algorithm to diff their contents. The patience algorithm is
commonly used to diff two text files on a line level, and it is helpful
because it groups together successful additions and deletions so as to
create a cleaner diff. This grouping algorithm is completely useless for
arrays, though, because it does not allow us to detect changed values
effectively.
Another solution which *does* allow us to detect changes, however, is
the diff-lcs gem, and that's exactly what this commit introduces.
0 commit comments