Replicate list changes

Imagine I have a list of items:

  - A
  - B
  - C

Now, from somewhere, the server tells my application that item B was deleted, but it only provides the whole new list, not the exact change data. Since WinRT ListView automatically updates the addition, removal and movement of items inside them, I would prefer not to update the support list and call Reset - INotifyCollectionChanged -event, as this animates every item that looks pretty dumb and rude. Instead, I want to calculate the steps needed to convert my local list to the list that I get from the server. (View as levenshtein distance, just not with the step count, but with the steps themselves)

e. g :.

  1. Delete element B
  2. Add new element D to position 3

How can I do it?

EDIT: matters in my case.

+7
list c # diff array-difference inotifycollectionchanged
source share
2 answers

Based on the @MihaiCaracostea page name, I was able to find a working working algorithm that works on any IList<T> . It even uses yield to calculate the difference when you list the changes.

The article can be found here , the actual source code (if you do not want to read how to do it) is here .

Beware, however, the algorithm runs in O (n²) time. There is certainly room for improvement in this area.

+3
source share

Look for items in the source list that are not in the resulting list: delete them.

Look for items in the list that are not in the source list: add them.

EDIT: Check out this code resource by showing the diff algorithm.

+2
source share

All Articles