liufengyun / hashdiff

Hashdiff is a ruby library to to compute the smallest difference between two hashes
MIT License
557 stars 63 forks source link

Showing same count as `=` #7

Closed zenati closed 7 years ago

zenati commented 10 years ago

Hello,

Actually Hashdiff can show +, - and ~. Is it possible to also show same counts in the diff as = ?

example output:

['-', 'b', 2], ['+', 'a', 4], ['=', 'c', 3, 3], ['~', 'd', 3, 8] 

Thanks.

dennisfaust commented 10 years ago

I quickly hacked up a simple version of what you are asking for in my fork. See if that meets your needs. It's not very sophisticated since it does not return matching hashes or arrays, only matching lowest level items. But it's a start.

liufengyun commented 10 years ago

It's a nice to have feature. While @dennisfaust proposed a simple version to report common primitive values, a more complex and reasonable version should return matching hashes and arrays. I'm still thinking how to do that in a simple way.

Any inputs are welcome.

dennisfaust commented 10 years ago

Recursion makes any use of the LCS table(s) a bit tricky. A crude but effective alternative would be to have a method 'same' which takes (a, b, diff_array) and returns an array containing the similarities by analyzing diff_array. Anything not in diff_array would be a similarity.

AAverin commented 8 years ago

Was that feature implemented in the end? Would be very nice to have it

pchaganti commented 8 years ago

:+1:

liufengyun commented 8 years ago

Thanks for your interest in this lib. I'm wondering what would you like to be the output in following case:

diff({a: {x: 2} }, {a: {x: 2} })

Possible result A:

[['=', 'a', {x: 2}]]

Possible result B:

[['=', 'a.x', 2]]

To me, the result A is more natural, but it means the algorithm needs to traverse the object twice -- first check if they are exactly equal(without =); if not, parse again to get all the = cases.