Skip to content

Commit

Permalink
Turn back the name of identifier to differenceIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed Aug 12, 2018
1 parent 7ab94c3 commit e38cf35
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 57 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ Documentation is generated by [jazzy](https://github.com/realm/jazzy).

### Example codes
The type of the element that to take the differences must be conform to the `Differentiable` protocol.
The `identifier`'s type is determined generic by the associated type:
The `differenceIdentifier`'s type is determined generic by the associated type:
```swift
struct User: Differentiable {
let id: Int
let name: String

var identifier: Int {
var differenceIdentifier: Int {
return id
}

Expand Down Expand Up @@ -150,7 +150,7 @@ Made a fair comparison as much as possible in features and performance with othe
鈿狅笍 This does `NOT` determine superiority or inferiority of the frameworks. I know that each framework has different benefits.
The frameworks and its version that compared is below.

- [DifferenceKit](https://github.com/ra1028/DifferenceKit) - 0.3.0
- [DifferenceKit](https://github.com/ra1028/DifferenceKit) - master
- [RxDataSources](https://github.com/RxSwiftCommunity/RxDataSources) ([Differentiator](https://github.com/RxSwiftCommunity/RxDataSources/tree/master/Sources/Differentiator)) - 3.0.2
- [FlexibleDiff](https://github.com/RACCommunity/FlexibleDiff) - 0.0.5
- [IGListKit](https://github.com/Instagram/IGListKit) - 3.4.0
Expand Down
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
2 changes: 1 addition & 1 deletion docs/Extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-11)</p>
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-13)</p>
<p>Generated by <a class="link" href="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/realm/jazzy" target="_blank" rel="external">jazzy 鈾櫕 v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Extensions/UICollectionView.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-11)</p>
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-13)</p>
<p>Generated by <a class="link" href="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/realm/jazzy" target="_blank" rel="external">jazzy 鈾櫕 v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Extensions/UITableView.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-11)</p>
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-13)</p>
<p>Generated by <a class="link" href="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/realm/jazzy" target="_blank" rel="external">jazzy 鈾櫕 v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-11)</p>
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-13)</p>
<p>Generated by <a class="link" href="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/realm/jazzy" target="_blank" rel="external">jazzy 鈾櫕 v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
18 changes: 9 additions & 9 deletions docs/Protocols/Differentiable.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ <h1>Differentiable</h1>
<li class="item">
<div>
<code>
<a name="/s:13DifferenceKit14DifferentiableP10Identifier"></a>
<a name="//apple_ref/swift/Alias/Identifier" class="dashAnchor"></a>
<a class="token" href="#/s:13DifferenceKit14DifferentiableP10Identifier">Identifier</a>
<a name="/s:13DifferenceKit14DifferentiableP0A10Identifier"></a>
<a name="//apple_ref/swift/Alias/DifferenceIdentifier" class="dashAnchor"></a>
<a class="token" href="#/s:13DifferenceKit14DifferentiableP0A10Identifier">DifferenceIdentifier</a>
</code>
</div>
<div class="height-container">
Expand All @@ -108,7 +108,7 @@ <h1>Differentiable</h1>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">associatedtype</span> <span class="kt">Identifier</span> <span class="p">:</span> <span class="kt">Hashable</span></code></pre>
<pre class="highlight swift"><code><span class="kd">associatedtype</span> <span class="kt">DifferenceIdentifier</span> <span class="p">:</span> <span class="kt">Hashable</span></code></pre>

</div>
</div>
Expand All @@ -118,9 +118,9 @@ <h4>Declaration</h4>
<li class="item">
<div>
<code>
<a name="/s:13DifferenceKit14DifferentiableP10identifier10IdentifierQzvp"></a>
<a name="//apple_ref/swift/Property/identifier" class="dashAnchor"></a>
<a class="token" href="#/s:13DifferenceKit14DifferentiableP10identifier10IdentifierQzvp">identifier</a>
<a name="/s:13DifferenceKit14DifferentiableP20differenceIdentifier0aE0Qzvp"></a>
<a name="//apple_ref/swift/Property/differenceIdentifier" class="dashAnchor"></a>
<a class="token" href="#/s:13DifferenceKit14DifferentiableP20differenceIdentifier0aE0Qzvp">differenceIdentifier</a>
</code>
<span class="declaration-note">
Default implementation
Expand All @@ -143,7 +143,7 @@ <h4>Default聽Implementation</h4>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="k">var</span> <span class="nv">identifier</span><span class="p">:</span> <span class="nf">Identifier</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>
<pre class="highlight swift"><code><span class="k">var</span> <span class="nv">differenceIdentifier</span><span class="p">:</span> <span class="nf">DifferenceIdentifier</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

</div>
</div>
Expand Down Expand Up @@ -216,7 +216,7 @@ <h4>Return Value</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-11)</p>
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-13)</p>
<p>Generated by <a class="link" href="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/realm/jazzy" target="_blank" rel="external">jazzy 鈾櫕 v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/DifferentiableSection.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-11)</p>
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-13)</p>
<p>Generated by <a class="link" href="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/realm/jazzy" target="_blank" rel="external">jazzy 鈾櫕 v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Structs.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ <h4>Declaration</h4>
<p>A type-erased differentiable value.</p>

<p>The <code>AnyDifferentiable</code> type hides the specific underlying types.
Associated type <code>Identifier</code> is erased by <code>AnyHashable</code>.
<code>DifferenceIdentifier</code> type is erased by <code>AnyHashable</code>.
The comparisons of whether has updated is forwards to an underlying differentiable value.</p>

<p>You can store mixed-type elements in collection that require <code><a href="Protocols/Differentiable.html">Differentiable</a></code> conformance by
Expand Down Expand Up @@ -309,7 +309,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-11)</p>
<p>&copy; 2018 <a class="link" href="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/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-08-13)</p>
<p>Generated by <a class="link" href="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/realm/jazzy" target="_blank" rel="external">jazzy 鈾櫕 v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit e38cf35

Please sign in to comment.