Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Heckel algorithm doesn't detect replaces? #16

Closed
benqo opened this issue Jun 4, 2018 · 3 comments
Closed

Heckel algorithm doesn't detect replaces? #16

benqo opened this issue Jun 4, 2018 · 3 comments

Comments

@benqo
Copy link

benqo commented Jun 4, 2018

Hi,

I have a problem with the Hecker algorithm, I think it doesn't detect replaces correctly. A simple example:

diff(old: Array("abc"), new: Array("adc"))
This will return delete at 1 and insert at 1.

Using WagnerFischer, it works as expected:
diff(old: Array("abc"), new: Array("adc"), algorithm: WagnerFischer())
This returns replace at 1.

Is this algorithm specific or just a bug?

Thanks!

@onmyway133
Copy link
Owner

onmyway133 commented Jun 12, 2018

@benqo Hi, to make it work like you describe, then we need a function to merge delete and insert changes at the same index to form a update change.

However, how can we tell if an object has been changed or not? The way DeepDiff works now is to base on the hashValue to tell if we are talking about the same object, usually we have object ID for uniqueness, and use Equatable conformance to tell if any of its properties have changed, you can take a look at https://github.com/onmyway133/DeepDiff/blob/master/DeepDiffTests/HeckelTests.swift#L55

This was referenced Jun 12, 2018
@benqo
Copy link
Author

benqo commented Jun 14, 2018

@onmyway133 thanks! Tried it again with my Hashable struct and works as expected. It detects if an object is replaced with a new (different) one or the same one is just updated.

@onmyway133
Copy link
Owner

@benqo Glad that it works for you 🥂

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

No branches or pull requests

2 participants