hashdiff icon indicating copy to clipboard operation
hashdiff copied to clipboard

Getting (+-) instead of diff (tilde) when comparing arrays

Open stripedpumpkin opened this issue 4 years ago • 5 comments

Hello. I find the following behavior (using Hashdiff 1.0.1) somewhat unexpected:

Hashdiff.diff(%w[a b c], %w[a b d])
=> [["-", "[2]", "c"], ["+", "[2]", "d"]]

Would not it be better to get

Hashdiff.diff(%w[a b c], %w[a b d])
=> [["~", "[2]", "c", "d"]]

?

Is there an option to get this behavior ?

Thanks for reading!

stripedpumpkin avatar Jun 09 '20 08:06 stripedpumpkin

I think it's possible to achieve that. It will be much appreciated if someone can give a hand on this.

liufengyun avatar Jun 10 '20 17:06 liufengyun

This does it:

Hashdiff.diff(%w[a b c], %w[a b d], use_lcs: false)

krzysiek1507 avatar Jun 10 '20 17:06 krzysiek1507

This does it:

Hashdiff.diff(%w[a b c], %w[a b d], use_lcs: false)

This is a workaround. I'm wondering if it is possible to make the algorithm smarter. Conceptually, it seems possible.

liufengyun avatar Jun 10 '20 17:06 liufengyun

Does LCS algorithm have a strict specification?

krzysiek1507 avatar Jun 10 '20 18:06 krzysiek1507

Does LCS algorithm have a strict specification?

I don't think it has. The tests + implementation are the de facto spec. In this case, the algorithm performs better, it might be acceptable to users even if it differs from previous results.

liufengyun avatar Jun 10 '20 18:06 liufengyun