Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stripedpumpkin opened this issue Jun 9, 2020 · 5 comments
Open

Comments

@stripedpumpkin
Copy link

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!

@liufengyun
Copy link
Owner

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

@krzysiek1507
Copy link
Collaborator

This does it:

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

@liufengyun
Copy link
Owner

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.

@krzysiek1507
Copy link
Collaborator

krzysiek1507 commented Jun 10, 2020

Does LCS algorithm have a strict specification?

@liufengyun
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants