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
StagedChangesetfrom 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.
Note
The data and changes each changeset contains are represents the middle of whole the changes. Each changes are from the previous stage.
Complexity
O(n)
Declaration
Swift
@inlinable init(source: Collection, target: Collection)Parameters
sourceA source collection to calculate differences.
targetA target collection to calculate differences.
-
Creates a new
StagedChangesetfrom 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.
Note
The data and changes each changeset contains are represents the middle of whole the changes. Each changes are from the previous stage.
Complexity
O(n)
Declaration
Swift
@inlinable init(source: Collection, target: Collection, section: Int)Parameters
sourceA source collection to calculate differences.
targetA target collection to calculate differences.
sectionAn Int value to use as section index (or offset) of element.
-
Creates a new
StagedChangesetfrom 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.
Note
The data and changes each changeset contains are represents the middle of whole the changes. Each changes are from the previous stage.
Complexity
O(n)
Declaration
Swift
@inlinable init(source: Collection, target: Collection)Parameters
sourceA source sectioned collection to calculate differences.
targetA target sectioned collection to calculate differences.
-
Declaration
Swift
public typealias Element = Changeset<Collection> -
Declaration
Swift
@inlinable public init() -
Declaration
Swift
@inlinable public var startIndex: Int { get } -
Declaration
Swift
@inlinable public var endIndex: Int { get } -
Declaration
Swift
@inlinable public func index(after i: Int) -> Int -
Declaration
Swift
@inlinable public subscript(position: Int) -> Changeset<Collection> { get set }
-
Declaration
Swift
@inlinable public static func == (lhs: StagedChangeset, rhs: StagedChangeset) -> Bool
-
Declaration
Swift
@inlinable public init(arrayLiteral elements: Changeset<Collection>...)
-
Declaration
Swift
public var debugDescription: String { get }
View on GitHub
StagedChangeset Structure Reference