Inferring diff between objects starting from patch applied to one of them
I would like to know if there are any known approaches other than the naive algorithm to this kind of problem I need to solve.
I have two objects of the same type, o1 and o2, containing some fields, f1, f2 and f3:
o1:
f1: A
f2: B
f3: C
o2:
f1: D
f2: B
f3: null
Now what I need is to figure out 开发者_如何学编程what changes happen in o2given a patch I receive that makes o1 equal to o2 (in terms of value equality on their fields). Example:
- Patch: f1 = D, f3 = null In this case I should infer that nothing has changed in o2, since applying this patch to o1 makes it identical to the current state of o2
- Patch: f1 = D, f3 = E In this case I should infer that the change in o2 is just f3 = E
- Patch: f1 = D In this case I should infer that the change in o2 is just f1 = C
I think the three examples above cover all cases. Now the naive algorithm would be to apply the patch on o1, and then diff o2 against the patched o1 to figure out the differences, but I'm wondering if there's a different algorithm or an optimized way to implement this one.
精彩评论