ListDiff
0.0.1
Paul Heckel のアルゴリズムに基づく軽量の O(n) 差分アルゴリズム。これは汎用の BidirectionCollection の上に構築されており、UIKit ベースの API にフレンドリーなサポートを提供します。
このリポジトリのクローンを作成し、 ListDiffExample
を実行すると、ListDiff によって提供されるコレクション ビューのアニメーションを確認できます。
print ( ListDiff . diffing ( oldData : " laksjdzcxlkawiey " , newData : " xclvkbyoieuwyrck " ) )
collectionView . animateItemChanges ( oldData : oldData , newData : newData ) {
dataSource = newData
}
Swiftのコレクションとの比較の違い
基本アルゴリズム | 注文 | 500要素 | 10,000 個の要素 | |
---|---|---|---|---|
リストの差分 | ヘッケル | の上) | 0.0037s | 0.0736s |
Swift.CollectionDifference | マイヤーズ | O(ND) | 0.0112s | 4.7747s |
ベンチマークはここで見ることができます。
$ swift run -c release ListDiffBenchmark
name time std iterations
----------------------------------------------------------------------------
ListDiff 500 elements 3719045.000 ns ± 11.13 % 377
ListDiff 10,000 elements 73628145.000 ns ± 1.01 % 17
CollectionDifference 500 elements 11225107.000 ns ± 4.66 % 120
CollectionDifference 10,000 elements 4774718233.000 ns ± 0.67 % 2
Xcode メニューのFile > Swift Packages > Add Package Dependency
を選択し、GUI でリポジトリ URL を入力します。
Repository: https://github.com/zzzzeu/ListDiff
Package.swift
の依存関係に以下を追加します。
. package ( url : " https://github.com/zzzzeu/ListDiff.git " , from : " 0.0.1 " )