ListDiff
0.0.1
基於 Paul Heckel 演算法的輕量級 O(n) 差分演算法。它建立在通用 Bi DirectionCollection 之上,為基於 UIKit 的 API 提供友善支援。
您可以克隆此儲存庫並執行ListDiffExample
以查看 ListDiff 提供的集合視圖動畫。
print ( ListDiff . diffing ( oldData : " laksjdzcxlkawiey " , newData : " xclvkbyoieuwyrck " ) )
collectionView . animateItemChanges ( oldData : oldData , newData : newData ) {
dataSource = newData
}
與 Swift 的 Collection 相比差異
基礎演算法 | 命令 | 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 " )