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.

    Declaration

    Swift

    @inlinable
    public init<C>(_ changesets: C) where C : Collection, C.Element == Changeset<Collection>

    Parameters

    changesets

    The collection of Changeset.

  • 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.

    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

    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.

    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

    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.

    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

    source

    A source sectioned collection to calculate differences.

    target

    A 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 mutating func replaceSubrange<C, R>(_ subrange: R, with newElements: C) where C : Collection, R : RangeExpression, C.Element == Changeset<Collection>, R.Bound == Int
  • Declaration

    Swift

    @inlinable
    public static func == (lhs: StagedChangeset, rhs: StagedChangeset) -> Bool
  • Declaration

    Swift

    public var debugDescription: String { get }