ListDiff is a Swift port of IGListKit's IGListDiff. It is an implementation of an algorithm by Paul Heckel that calculates the diff between 2 arrays.
The motivation for this project came from the following challenge which I learnt about it from Ryan Nystrom's talk at iOSConf.SG.
swift package generate-xcodeproj
pod 'ListDiff'
github "lxcid/ListDiff" "master"
import ListDiff
extension Int : Diffable {
public var diffIdentifier: AnyHashable {
return self
}
}
let o = [0, 1, 2]
let n = [2, 1, 3]
let result = List.diffing(oldArray: o, newArray: n)
// result.hasChanges == true
// result.deletes == IndexSet(integer: 0)
// result.inserts == IndexSet(integer: 2)
// result.moves == [List.MoveIndex(from: 2, to: 0), List.MoveIndex(from: 1, to: 1)]
// result.changeCount == 4
During the port, I made several decisions which I would like to rationalize here.
struct
more, so only List.Entry
is a (final) class as we need reference to its instances.link |
Stars: 238 |
Last commit: 3 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics