StagedChangeset
public struct StagedChangeset<Collection> where Collection : Collection
An ordered collection of Changeset
as staged set of changes in the sectioned collection.
The order is representing the stages of changesets.
We know that there are combination of changes that crash when applied simultaneously
in batch-updates of UI such as UITableView or UICollectionView.
The StagedChangeset
created from the two collection is split at the minimal stages
that can be perform batch-updates with no crashes.
Example for calculating differences between the two linear collections.
extension String: Differentiable {}
let source = ["A", "B", "C"]
let target = ["B", "C", "D"]
let changeset = StagedChangeset(source: source, target: target)
print(changeset.isEmpty) // prints "false"
Example for calculating differences between the two sectioned collections.
let source = [
Section(model: "A", elements: ["😉"]),
]
let target = [
Section(model: "A", elements: ["😉, 😺"]),
Section(model: "B", elements: ["😪"])
]
let changeset = StagedChangeset(source: sectionedSource, target: sectionedTarget)
print(changeset.isEmpty) // prints "false"
-
Creates a new
StagedChangeset
from the two collections.Calculate the differences between the collections using the algorithm optimized based on the Paul Heckel’s diff algorithm.
Note
This algorithm can compute the differences at high performance with O(n) complexity. However, not always calculates the shortest differences.
Note
If the elements with the same identifier duplicated, the algorithm calculates the moves at best effort, and rest of the duplicates as insertion or deletion.
Complexity
O(n)
Declaration
Swift
public init(source: Collection, target: Collection)
Parameters
source
A source collection to calculate differences.
target
A target collection to calculate differences.
-
Creates a new
StagedChangeset
from the two collections.Calculate the differences between the collections using the algorithm optimized based on the Paul Heckel’s diff algorithm.
Note
This algorithm can compute the differences at high performance with O(n) complexity. However, not always calculates the shortest differences.
Note
If the elements with the same identifier duplicated, the algorithm calculates the moves at best effort, and rest of the duplicates as insertion or deletion.
Complexity
O(n)
Declaration
Swift
public init(source: Collection, target: Collection, section: Int)
Parameters
source
A source collection to calculate differences.
target
A target collection to calculate differences.
section
An Int value to use as section index (or offset) of element.
-
Creates a new
StagedChangeset
from the two sectioned collections.Calculate the differences between the collections using the algorithm optimized based on the Paul Heckel’s diff algorithm.
Note
This algorithm can compute the differences at high performance with O(n) complexity. However, not always calculates the shortest differences.
Note
If the elements with the same identifier duplicated, the algorithm calculates the moves at best effort, and rest of the duplicates as insertion or deletion.
Complexity
O(n)
Declaration
Swift
public init(source: Collection, target: Collection)
Parameters
source
A source sectioned collection to calculate differences.
target
A target sectioned collection to calculate differences.
-
Declaration
Swift
public init()
-
Declaration
Swift
public var startIndex: Int { get }
-
Declaration
Swift
public var endIndex: Int { get }
-
Declaration
Swift
public func index(after i: Int) -> Int
-
Declaration
Swift
public subscript(position: Int) -> Changeset<Collection> { get set }
-
Declaration
Swift
public mutating func replaceSubrange<C, R>(_ subrange: R, with newElements: C) where C : Collection, R : RangeExpression, C.Element == Changeset<Collection>, R.Bound == Int
-
Declaration
Swift
public static func == (lhs: StagedChangeset, rhs: StagedChangeset) -> Bool
-
Declaration
Swift
public init(arrayLiteral elements: Changeset<Collection>...)
-
Declaration
Swift
public var debugDescription: String { get }