Skip to content

Commit

Permalink
Revert " is now renamed to"
Browse files Browse the repository at this point in the history
This reverts commit e23c3b7.
  • Loading branch information
Sameesunkaria committed Aug 12, 2018
1 parent 7ab94c3 commit 3549c1b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions Sources/Algorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
/// - Complexity: O(n)
public init(source: Collection, target: Collection) {
typealias Section = Collection.Element
typealias SectionIdentifier = Collection.Element.Model.Identifier
typealias SectionIdentifier = Collection.Element.Model.DifferenceIdentifier
typealias Element = Collection.Element.Collection.Element
typealias ElementIdentifier = Collection.Element.Collection.Element.Identifier
typealias ElementIdentifier = Collection.Element.Collection.Element.DifferenceIdentifier

let sourceSections = ContiguousArray(source)
let targetSections = ContiguousArray(target)
Expand Down Expand Up @@ -167,7 +167,7 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
for sourceElementIndex in contiguousSourceSections[sourceSectionIndex].indices {
let sourceElementPath = ElementPath(element: sourceElementIndex, section: sourceSectionIndex)
let sourceElement = contiguousSourceSections[sourceElementPath]
flattenSourceIdentifiers.append(sourceElement.identifier)
flattenSourceIdentifiers.append(sourceElement.differenceIdentifier)
flattenSourceElementPaths.append(sourceElementPath)
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
let targetElements = contiguousTargetSections[targetSectionIndex]

for targetElementIndex in targetElements.indices {
var targetIdentifier = targetElements[targetElementIndex].identifier
var targetIdentifier = targetElements[targetElementIndex].differenceIdentifier
let key = TableKey(pointer: &targetIdentifier)

switch sourceOccurrencesTable[key] {
Expand Down Expand Up @@ -402,19 +402,19 @@ private func differentiate<E, D: Differentiable, I>(

var sourceTraces = ContiguousArray<Trace<Int>>()
var targetReferences = ContiguousArray<Int?>(repeating: nil, count: target.count)
var sourceIdentifiers = ContiguousArray<D.Identifier>()
var sourceIdentifiers = ContiguousArray<D.DifferenceIdentifier>()

sourceIdentifiers.reserveCapacity(source.count)
sourceTraces.reserveCapacity(source.count)

for sourceElement in source {
sourceTraces.append(Trace())
sourceIdentifiers.append(differentiable(sourceElement).identifier)
sourceIdentifiers.append(differentiable(sourceElement).differenceIdentifier)
}

sourceIdentifiers.withUnsafeBufferPointer { bufferPointer in
// The pointer and the table key are for optimization.
var sourceOccurrencesTable = [TableKey<D.Identifier>: Occurrence](minimumCapacity: source.count * 2)
var sourceOccurrencesTable = [TableKey<D.DifferenceIdentifier>: Occurrence](minimumCapacity: source.count * 2)

// Record the index where the element was found in source collection into occurrences table.
for sourceIndex in sourceIdentifiers.indices {
Expand All @@ -436,7 +436,7 @@ private func differentiate<E, D: Differentiable, I>(

// Record the target index and the source index that the element having the same identifier.
for targetIndex in target.indices {
var targetIdentifier = differentiable(target[targetIndex]).identifier
var targetIdentifier = differentiable(target[targetIndex]).differenceIdentifier
let key = TableKey(pointer: &targetIdentifier)

switch sourceOccurrencesTable[key] {
Expand Down
6 changes: 3 additions & 3 deletions Sources/AnyDifferentiable.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// A type-erased differentiable value.
///
/// The `AnyDifferentiable` type hides the specific underlying types.
/// Associated type `Identifier` is erased by `AnyHashable`.
/// `DifferenceIdentifier` type is erased by `AnyHashable`.
/// The comparisons of whether has updated is forwards to an underlying differentiable value.
///
/// You can store mixed-type elements in collection that require `Differentiable` conformance by
Expand All @@ -26,7 +26,7 @@ public struct AnyDifferentiable: Differentiable {
/// The value wrapped by this instance.
public let base: Any
/// A type-erased identifier value for difference calculation.
public let identifier: AnyHashable
public let differenceIdentifier: AnyHashable

private let isContentEqualTo: (AnyDifferentiable) -> Bool

Expand All @@ -36,7 +36,7 @@ public struct AnyDifferentiable: Differentiable {
/// - base: A differentiable value to wrap.
public init<D: Differentiable>(_ base: D) {
self.base = base
self.identifier = AnyHashable(base.identifier)
self.differenceIdentifier = AnyHashable(base.differenceIdentifier)

self.isContentEqualTo = { source in
guard let sourceBase = source.base as? D else { return false }
Expand Down
6 changes: 3 additions & 3 deletions Sources/Differentiable.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// Represents the value that identified and can be compared to whether has updated.
public protocol Differentiable {
/// A type representing the identifier.
associatedtype Identifier: Hashable
associatedtype DifferenceIdentifier: Hashable

/// An identifier value for difference calculation.
var identifier: Identifier { get }
var differenceIdentifier: DifferenceIdentifier { get }

/// Indicate whether the content of `self` is equals to the content of
/// the given source value.
Expand Down Expand Up @@ -33,7 +33,7 @@ public extension Differentiable where Self: Equatable {

public extension Differentiable where Self: Hashable {
/// The `self` value as an identifier for difference calculation.
var identifier: Self {
var differenceIdentifier: Self {
return self
}
}
12 changes: 6 additions & 6 deletions Tests/AnyDifferentiableTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ final class AnyDifferentiableTestCase: XCTestCase {
let d1 = AnyDifferentiable(base1)
let d2 = AnyDifferentiable(base1)

XCTAssertEqual(d1.identifier.hashValue, d2.identifier.hashValue)
XCTAssertEqual(d1.identifier, d2.identifier)
XCTAssertEqual(d1.differenceIdentifier.hashValue, d2.differenceIdentifier.hashValue)
XCTAssertEqual(d1.differenceIdentifier, d2.differenceIdentifier)
XCTAssertTrue(d1.isContentEqual(to: d2))

let base2 = M(1, false)

let d3 = AnyDifferentiable(base1)
let d4 = AnyDifferentiable(base2)

XCTAssertNotEqual(d3.identifier.hashValue, d4.identifier.hashValue)
XCTAssertNotEqual(d3.identifier, d4.identifier)
XCTAssertNotEqual(d3.differenceIdentifier.hashValue, d4.differenceIdentifier.hashValue)
XCTAssertNotEqual(d3.differenceIdentifier, d4.differenceIdentifier)
XCTAssertFalse(d3.isContentEqual(to: d4))

let base3 = M(1, true)

let d5 = AnyDifferentiable(base2)
let d6 = AnyDifferentiable(base3)

XCTAssertEqual(d5.identifier.hashValue, d6.identifier.hashValue)
XCTAssertEqual(d5.identifier, d6.identifier)
XCTAssertEqual(d5.differenceIdentifier.hashValue, d6.differenceIdentifier.hashValue)
XCTAssertEqual(d5.differenceIdentifier, d6.differenceIdentifier)
XCTAssertFalse(d5.isContentEqual(to: d6))
}
}
4 changes: 2 additions & 2 deletions Tests/SectionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ final class SectionTestCase: XCTestCase {
let s1 = Section(model: D.a, elements: [0])
let s2 = Section(model: s1.model, elements: s1.elements)

XCTAssertEqual(s1.model.identifier, s2.model.identifier)
XCTAssertEqual(s1.model.identifier.hashValue, s2.model.identifier.hashValue)
XCTAssertEqual(s1.model.differenceIdentifier, s2.model.differenceIdentifier)
XCTAssertEqual(s1.model.differenceIdentifier.hashValue, s2.model.differenceIdentifier.hashValue)
XCTAssertEqual(s1.elements, s2.elements)
}
}
2 changes: 1 addition & 1 deletion Tests/TestTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct M: Differentiable, Equatable {
self.b = b
}

var identifier: Int {
var differenceIdentifier: Int {
return i
}
}
Expand Down

0 comments on commit 3549c1b

Please sign in to comment.