Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazuhiro Hayashi committed Feb 26, 2017
2 parents 5a1af47 + 827725c commit 3811d76
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ tableView.diff.reload(to: container)
You don't have to manage how to update incrementally. That enables to pileline the process.

# How dose it work?
EditDistance calculates a difference between two arrays and converts it to the incremental update processes of UITableView or UICollectionView.
EditDistance calculates a difference between two arrays and converts it into an incremental update processes of UITableView or UICollectionView.

The differences are calculated with "Edit Distance Algorithm". There are the many ways and almost all of them runs in polynominal time.
The differences are calculated with [**Edit Distance Algorithm**](https://en.wikipedia.org/wiki/Edit_distance). There are many ways to calculate and almost all of them run in polynominal time.

- Dynamic Programming (*O(NM)*)
- Mayer's Algorithm (*O(ND)*)
Expand All @@ -58,7 +58,7 @@ The differences are calculated with "Edit Distance Algorithm". There are the man

*N* and M is sequence sizes of each array. D is edit distance and P is the number of deletion.

In our context, Wu' Algorithm seems to be the best algorithm. It has better performance than the others when your app has many items to show on UTableView and add or delete a few items.
In our context, Wu' Algorithm seems to be the best algorithm. It has better performance than the others when your app has many items and add or delete a few items. (e.g. autopager, access history or notification)

# Pros and Cons
Calculation in this library is not always reasonable to update UI. I recommend that your app calculate edit distance in background and update UI in main thread.
Expand Down Expand Up @@ -194,6 +194,24 @@ dataSource = nextDataSource
tableView.diff.reload(with: container)
```

# Performance
Wu's algorithm is recommended in this library. The actual speed depends on the number of differences between two arrays and the cost of "==" the elements have. The followings are some avarage speed for reference. They were executed on iPhone7, iOS 10.2 Simulator. The sample arrays is composed of random UUID Strings.

- from 100 items to 120 items (only addition), avg: 0.002 sec
- from 100 items to 120 items (addition and deletion), avg: 0.002 sec
- from 100 items to 200 items (only addition), avg: 0.003 ms
- from 100 items to 200 items (addition and deletion), avg: 0.003 ms
- from 1000 items to 1050 items (only addition), avg: 0.010 sec
- from 1000 items to 1050 items (addition and deletion), avg: 0.011 sec
- from 1000 items to 1200 items (only addition), avg: 0.010 sec
- from 1000 items to 1200 items (addition and deletion), avg: 0.030 ms
- from 10000 items to 10100 items (only addition), avg: 0.080 ms
- from 10000 items to 10100 items (addition and deletion), avg: 0.088 0ms
- from 10000 items to 12000 items (only addition), avg: 0.105 ms
- from 10000 items to 12000 items (addition and deletion), avg: 0.194 ms

Test Cases are [here](https://github.com/kazuhiro4949/EditDistance/blob/master/EditDistanceTests/WuTests.swift). You can take reexamintion with them.

# License

Copyright (c) 2017 Kazuhiro Hayashi
Expand Down

0 comments on commit 3811d76

Please sign in to comment.