Optimal difference between object lists in Java

I have a list of Java objects on my server that is sent to the client through some serialization mechanism. From time to time, the list of objects is updated on the server, that is, some objects are added, some are deleted, and others simply change their place in the List. I also want to update the list on the client side, but I will send the least possible data. In particular, I do not want to resend objects that are already available on the client.

Is there a library available that will create some kind of diff from two lists, so that I can only send the difference and new objects by wire?

I found several Java implementations for the unix diff command, but this algorithm is impractical for reordering. i.e. [A, B, C] → [C, B, A] can be sent as soon as the location changes [1-> 3] [3-> 1], while diff will want to resend all objects A and C (as much as I understand).

+3
source share
4 answers

For now, I will simply send a complete list by wire, but instead of objects, I use only a unique identifier. If the client does not have a local object, it requests it using the identifier.

This, of course, is less beautiful than the optimal algorithm, but it has the expected result: expensive objects are sent only once by wire.

0
source

, , , , , , .

, , , .

, , , , , . , / , , .

+3

"", , -, , , , , ( ).

/ , , , , , . , , , , , , .

+3

JaVers lib (http://javers.org) .

Diff diff = javers.compare(list1, list2);

Diff contains a list of changes, such as: adding an object, deleting an object, changing the index

+1
source

Source: https://habr.com/ru/post/1741406/


All Articles