-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathindex.html
749 lines (668 loc) · 38.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
<!DOCTYPE html>
<html lang="en">
<head>
<title>DifferenceKit Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset="utf-8">
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
<script src="js/lunr.min.js" defer></script>
<script src="js/typeahead.jquery.js" defer></script>
<script src="js/jazzy.search.js" defer></script>
</head>
<body>
<a title="DifferenceKit Reference"></a>
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="index.html">
DifferenceKit Docs
</a>
(100% documented)
</p>
<p class="header-col--secondary">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</p>
<p class="header-col header-col--secondary">
<a class="header-link" href="https://github.com/ra1028/DifferenceKit">
<img class="header-icon" src="img/gh.png"/>
View on GitHub
</a>
</p>
</header>
<p class="breadcrumbs">
<a class="breadcrumb" href="index.html">DifferenceKit Reference</a>
<img class="carat" src="img/carat.png" />
DifferenceKit Reference
</p>
<div class="content-wrapper">
<nav class="navigation">
<ul class="nav-groups">
<li class="nav-group-name">
<a class="nav-group-name-link" href="Diffing.html">Diffing</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/ContentEquatable.html">ContentEquatable</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/Differentiable.html">Differentiable</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/DifferentiableSection.html">DifferentiableSection</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/AnyDifferentiable.html">AnyDifferentiable</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/ArraySection.html">ArraySection</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/ElementPath.html">ElementPath</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/Optional.html">Optional</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Changeset.html">Changeset</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/StagedChangeset.html">StagedChangeset</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Structs/Changeset.html">Changeset</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="UI%20Extensions.html">UI Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/UITableView.html">UITableView</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Extensions/UICollectionView.html">UICollectionView</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section class="section">
<div class="section-content">
<p><img src="https://raw.githubusercontent.com/ra1028/DifferenceKit/master/assets/sample.gif" height="310" align="right"></p>
<p align="center">
<img src="https://raw.githubusercontent.com/ra1028/DifferenceKit/master/assets/logo.png" width="500">
</p>
<H4 align="center">
A fast and flexible O(n) difference algorithm framework for Swift collection.</br>
The algorithm is optimized based on the Paul Heckel’s algorithm.
</H4>
<p align="center">
<a href="https://developer.apple.com/swift"><img alt="Swift5" src="https://img.shields.io/badge/language-Swift5-orange.svg"/></a>
<a href="https://github.com/ra1028/DifferenceKit/releases/latest"><img alt="Release" src="https://img.shields.io/github/release/ra1028/DifferenceKit.svg"/></a>
<a href="https://cocoapods.org/pods/DifferenceKit"><img alt="CocoaPods" src="https://img.shields.io/cocoapods/v/DifferenceKit.svg"/></a>
<a href="https://github.com/Carthage/Carthage"><img alt="Carthage" src="https://img.shields.io/badge/Carthage-compatible-yellow.svg"/></a>
<a href="https://swift.org/package-manager"><img alt="Swift Package Manager" src="https://img.shields.io/badge/SwiftPM-compatible-yellowgreen.svg"/></a>
</br>
<a href="https://dev.azure.
com/ra1028/GitHub/_build/latest?definitionId=1&branchName=master"><img alt="Build Status" src="https://dev.azure.com/ra1028/GitHub/_apis/build/status/ra1028.DifferenceKit?branchName=master"/></a>
<a href="https://developer.apple.com/"><img alt="Platform" src="https://img.shields.io/badge/platform-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-green.svg"/></a>
<a href="https://github.com/ra1028/DifferenceKit/blob/master/LICENSE"><img alt="Lincense" src="http://img.shields.io/badge/License-Apache%202.0-black.svg"/></a>
</p>
<p><br></p>
<p align="center">
Made with ❤️ by <a href="https://github.com/ra1028">Ryo Aoyama</a> and <a href="https://github.com/ra1028/DifferenceKit/graphs/contributors">Contributors</a>
<br clear="all">
</p>
<hr>
<h2 id='features' class='heading'>Features</h2>
<p>💡 Fastest <strong>O(n)</strong> diffing algorithm optimized for Swift collection</p>
<p>💡 Calculate diffs for batch updates of list UI in <code>UIKit</code>, <code>AppKit</code> and <a href="https://github.com/TextureGroup/Texture">Texture</a></p>
<p>💡 Supports both linear and sectioned collection even if contains duplicates</p>
<p>💡 Supports <strong>all kind of diffs</strong> for animated UI batch updates</p>
<hr>
<h2 id='algorithm' class='heading'>Algorithm</h2>
<p>This is a diffing algorithm developed for <a href="https://github.com/ra1028/Carbon">Carbon</a>, works stand alone.<br>
The algorithm optimized based on the Paul Heckel’s algorithm.<br>
See also his paper <a href="https://dl.acm.org/citation.cfm?id=359467"><q>A technique for isolating differences between files</q></a> released in 1978.<br>
It allows all kind of diffs to be calculated in linear time <strong>O(n)</strong>.<br>
<a href="https://github.com/RxSwiftCommunity/RxDataSources">RxDataSources</a> and <a href="https://github.com/Instagram/IGListKit">IGListKit</a> are also implemented based on his algorithm. </p>
<p>However, in <code>performBatchUpdates</code> of <code>UITableView</code>, <code>UICollectionView</code>, etc, there are combinations of diffs that cause crash when applied simultaneously.<br>
To solve this problem, <code>DifferenceKit</code> takes an approach of split the set of diffs at the minimal stages that can be perform batch updates with no crashes.</p>
<p>Implementation is <a href="https://github.com/ra1028/DifferenceKit/blob/master/Sources/Algorithm.swift">here</a>.</p>
<hr>
<h2 id='getting-started' class='heading'>Getting Started</h2>
<ul>
<li><a href="https://ra1028.github.io/DifferenceKit">API Documentation</a></li>
<li><a href="https://github.com/ra1028/DifferenceKit/blob/master/Examples">Example Apps</a></li>
<li><a href="https://github.com/ra1028/DifferenceKit/blob/master/Benchmark">Benchmark</a></li>
<li><a href="https://github.com/ra1028/DifferenceKit/blob/master/DifferenceKit.playground/Contents.swift">Playground</a></li>
</ul>
<h2 id='basic-usage' class='heading'>Basic Usage</h2>
<p>The type of the element that to take diffs must be conform to the <code><a href="Protocols/Differentiable.html">Differentiable</a></code> protocol.<br>
The <code>differenceIdentifier</code>‘s type is generic associated type:</p>
<pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">User</span><span class="p">:</span> <span class="kt">Differentiable</span> <span class="p">{</span>
<span class="k">let</span> <span class="nv">id</span><span class="p">:</span> <span class="kt">Int</span>
<span class="k">let</span> <span class="nv">name</span><span class="p">:</span> <span class="kt">String</span>
<span class="k">var</span> <span class="nv">differenceIdentifier</span><span class="p">:</span> <span class="kt">Int</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">id</span>
<span class="p">}</span>
<span class="kd">func</span> <span class="nf">isContentEqual</span><span class="p">(</span><span class="n">to</span> <span class="nv">source</span><span class="p">:</span> <span class="kt">User</span><span class="p">)</span> <span class="o">-></span> <span class="kt">Bool</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">name</span> <span class="o">==</span> <span class="n">source</span><span class="o">.</span><span class="n">name</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre>
<p>In the case of definition above, <code>id</code> uniquely identifies the element and get to know the user updated by comparing equality of <code>name</code> of the elements in source and target.</p>
<p>There are default implementations of <code><a href="Protocols/Differentiable.html">Differentiable</a></code> for the types that conforming to <code>Equatable</code> or <code>Hashable</code>:</p>
<pre class="highlight swift"><code><span class="c1">// If `Self` conforming to `Hashable`.</span>
<span class="k">var</span> <span class="nv">differenceIdentifier</span><span class="p">:</span> <span class="k">Self</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">self</span>
<span class="p">}</span>
<span class="c1">// If `Self` conforming to `Equatable`.</span>
<span class="kd">func</span> <span class="nf">isContentEqual</span><span class="p">(</span><span class="n">to</span> <span class="nv">source</span><span class="p">:</span> <span class="k">Self</span><span class="p">)</span> <span class="o">-></span> <span class="kt">Bool</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">self</span> <span class="o">==</span> <span class="n">source</span>
<span class="p">}</span>
</code></pre>
<p>Therefore, you can simply:</p>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">String</span><span class="p">:</span> <span class="kt">Differentiable</span> <span class="p">{}</span>
</code></pre>
<p>Calculate the diffs by creating <code><a href="Structs/StagedChangeset.html">StagedChangeset</a></code> from two collections of elements conforming to <code><a href="Protocols/Differentiable.html">Differentiable</a></code>:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">source</span> <span class="o">=</span> <span class="p">[</span>
<span class="kt">User</span><span class="p">(</span><span class="nv">id</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Vincent"</span><span class="p">),</span>
<span class="kt">User</span><span class="p">(</span><span class="nv">id</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Jules"</span><span class="p">)</span>
<span class="p">]</span>
<span class="k">let</span> <span class="nv">target</span> <span class="o">=</span> <span class="p">[</span>
<span class="kt">User</span><span class="p">(</span><span class="nv">id</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Jules"</span><span class="p">),</span>
<span class="kt">User</span><span class="p">(</span><span class="nv">id</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Vincent"</span><span class="p">),</span>
<span class="kt">User</span><span class="p">(</span><span class="nv">id</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Butch"</span><span class="p">)</span>
<span class="p">]</span>
<span class="k">let</span> <span class="nv">changeset</span> <span class="o">=</span> <span class="kt">StagedChangeset</span><span class="p">(</span><span class="nv">source</span><span class="p">:</span> <span class="n">source</span><span class="p">,</span> <span class="nv">target</span><span class="p">:</span> <span class="n">target</span><span class="p">)</span>
</code></pre>
<p>If you want to include multiple types conforming to <code><a href="Protocols/Differentiable.html">Differentiable</a></code> in the collection, use <code><a href="Structs/AnyDifferentiable.html">AnyDifferentiable</a></code>:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">source</span> <span class="o">=</span> <span class="p">[</span>
<span class="kt">AnyDifferentiable</span><span class="p">(</span><span class="s">"A"</span><span class="p">),</span>
<span class="kt">AnyDifferentiable</span><span class="p">(</span><span class="kt">User</span><span class="p">(</span><span class="nv">id</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Vincent"</span><span class="p">))</span>
<span class="p">]</span>
</code></pre>
<p>In the case of sectioned collection, the section itself must have a unique identifier and be able to compare whether there is an update.<br>
So each section must conforming to <code><a href="Protocols/DifferentiableSection.html">DifferentiableSection</a></code> protocol, but in most cases you can use <code><a href="Structs/ArraySection.html">ArraySection</a></code> that general type conforming to it.<br>
<code><a href="Structs/ArraySection.html">ArraySection</a></code> requires a model conforming to <code><a href="Protocols/Differentiable.html">Differentiable</a></code> for diffing from other sections:</p>
<pre class="highlight swift"><code><span class="kd">enum</span> <span class="kt">Model</span><span class="p">:</span> <span class="kt">Differentiable</span> <span class="p">{</span>
<span class="k">case</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span>
<span class="p">}</span>
<span class="k">let</span> <span class="nv">source</span><span class="p">:</span> <span class="p">[</span><span class="kt">ArraySection</span><span class="o"><</span><span class="kt">Model</span><span class="p">,</span> <span class="kt">String</span><span class="o">></span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
<span class="kt">ArraySection</span><span class="p">(</span><span class="nv">model</span><span class="p">:</span> <span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="nv">elements</span><span class="p">:</span> <span class="p">[</span><span class="s">"A"</span><span class="p">,</span> <span class="s">"B"</span><span class="p">]),</span>
<span class="kt">ArraySection</span><span class="p">(</span><span class="nv">model</span><span class="p">:</span> <span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="nv">elements</span><span class="p">:</span> <span class="p">[</span><span class="s">"C"</span><span class="p">])</span>
<span class="p">]</span>
<span class="k">let</span> <span class="nv">target</span><span class="p">:</span> <span class="p">[</span><span class="kt">ArraySection</span><span class="o"><</span><span class="kt">Model</span><span class="p">,</span> <span class="kt">String</span><span class="o">></span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
<span class="kt">ArraySection</span><span class="p">(</span><span class="nv">model</span><span class="p">:</span> <span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="nv">elements</span><span class="p">:</span> <span class="p">[</span><span class="s">"D"</span><span class="p">,</span> <span class="s">"E"</span><span class="p">]),</span>
<span class="kt">ArraySection</span><span class="p">(</span><span class="nv">model</span><span class="p">:</span> <span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="nv">elements</span><span class="p">:</span> <span class="p">[</span><span class="s">"A"</span><span class="p">]),</span>
<span class="kt">ArraySection</span><span class="p">(</span><span class="nv">model</span><span class="p">:</span> <span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="nv">elements</span><span class="p">:</span> <span class="p">[</span><span class="s">"B"</span><span class="p">,</span> <span class="s">"C"</span><span class="p">])</span>
<span class="p">]</span>
<span class="k">let</span> <span class="nv">changeset</span> <span class="o">=</span> <span class="kt">StagedChangeset</span><span class="p">(</span><span class="nv">source</span><span class="p">:</span> <span class="n">source</span><span class="p">,</span> <span class="nv">target</span><span class="p">:</span> <span class="n">target</span><span class="p">)</span>
</code></pre>
<p>You can perform diffing batch updates of <code>UITableView</code> and <code>UICollectionView</code> using the created <code><a href="Structs/StagedChangeset.html">StagedChangeset</a></code>. </p>
<p>⚠️ <strong>Don’t forget</strong> to <strong>synchronously</strong> update the data referenced by the data-source, with the data passed in the <code>setData</code> closure. The diffs are applied in stages, and failing to do so is bound to create a crash:</p>
<pre class="highlight swift"><code><span class="n">tableView</span><span class="o">.</span><span class="nf">reload</span><span class="p">(</span><span class="nv">using</span><span class="p">:</span> <span class="n">changeset</span><span class="p">,</span> <span class="nv">with</span><span class="p">:</span> <span class="o">.</span><span class="n">fade</span><span class="p">)</span> <span class="p">{</span> <span class="n">data</span> <span class="k">in</span>
<span class="n">dataSource</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
<span class="p">}</span>
</code></pre>
<p>Batch updates using too large amount of diffs may adversely affect to performance.<br>
Returning <code>true</code> with <code>interrupt</code> closure then falls back to <code>reloadData</code>:</p>
<pre class="highlight swift"><code><span class="n">collectionView</span><span class="o">.</span><span class="nf">reload</span><span class="p">(</span><span class="nv">using</span><span class="p">:</span> <span class="n">changeset</span><span class="p">,</span> <span class="nv">interrupt</span><span class="p">:</span> <span class="p">{</span> <span class="nv">$0</span><span class="o">.</span><span class="n">changeCount</span> <span class="o">></span> <span class="mi">100</span> <span class="p">})</span> <span class="p">{</span> <span class="n">data</span> <span class="k">in</span>
<span class="n">dataSource</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
<span class="p">}</span>
</code></pre>
<H3 align="center">
<a href="https://ra1028.github.io/DifferenceKit">[See More Usage]</a>
</H3>
<hr>
<h2 id='comparison-with-other-frameworks' class='heading'>Comparison with Other Frameworks</h2>
<p>Made a fair comparison as much as possible in performance and features with other <strong>popular</strong> and <strong>awesome</strong> frameworks.<br>
This does <strong>NOT</strong> determine superiority or inferiority of the frameworks.<br>
I know that each framework has different benefits.<br>
The frameworks and its version that compared is below. </p>
<ul>
<li><a href="https://github.com/ra1028/DifferenceKit">DifferenceKit</a> - master</li>
<li><a href="https://github.com/RxSwiftCommunity/RxDataSources">RxDataSources</a> (<a href="https://github.com/RxSwiftCommunity/RxDataSources/tree/master/Sources/Differentiator">Differentiator</a>) - 4.0.1</li>
<li><a href="https://github.com/RACCommunity/FlexibleDiff">FlexibleDiff</a> - 0.0.8</li>
<li><a href="https://github.com/Instagram/IGListKit">IGListKit</a> - 3.4.0</li>
<li><a href="https://github.com/onmyway133/DeepDiff">DeepDiff</a> - 2.2.0</li>
<li><a href="https://github.com/tonyarnold/Differ">Differ</a> (<a href="https://github.com/wokalski/Diff.swift">Diff.swift</a>) - 1.4.3</li>
<li><a href="https://github.com/jflinter/Dwifft">Dwifft</a> - 0.9</li>
<li><a href="https://developer.apple.com/documentation/swift/collectiondifference">Swift.CollectionDifference</a> Swift 5.1</li>
</ul>
<h3 id='performance-comparison' class='heading'>Performance Comparison</h3>
<p>Benchmark project is <a href="https://github.com/ra1028/DifferenceKit/blob/master/Benchmark">here</a>.<br>
Performance was mesured by code compiled using <code>Xcode11.1</code> and <code>Swift 5.1</code> with <code>-O</code> optimization and run on <code>iPhone11 Pro simulator</code>.<br>
Use <code>Foundation.UUID</code> as an element of collections. </p>
<h4 id='from-5-000-elements-to-1-000-deleted-1-000-inserted-and-200-shuffled' class='heading'>- From 5,000 elements to 1,000 deleted, 1,000 inserted and 200 shuffled</h4>
<table><thead>
<tr>
<th style="text-align: left"></th>
<th style="text-align: right">Time(sec)</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">DifferenceKit</td>
<td style="text-align: right"><code>0.0019</code></td>
</tr>
<tr>
<td style="text-align: left">RxDataSources</td>
<td style="text-align: right"><code>0.0074</code></td>
</tr>
<tr>
<td style="text-align: left">IGListKit</td>
<td style="text-align: right"><code>0.0346</code></td>
</tr>
<tr>
<td style="text-align: left">FlexibleDiff</td>
<td style="text-align: right"><code>0.0161</code></td>
</tr>
<tr>
<td style="text-align: left">DeepDiff</td>
<td style="text-align: right"><code>0.0373</code></td>
</tr>
<tr>
<td style="text-align: left">Differ</td>
<td style="text-align: right"><code>1.0581</code></td>
</tr>
<tr>
<td style="text-align: left">Dwifft</td>
<td style="text-align: right"><code>0.4732</code></td>
</tr>
<tr>
<td style="text-align: left">Swift.CollectionDifference</td>
<td style="text-align: right"><code>0.0620</code></td>
</tr>
</tbody></table>
<h4 id='from-100-000-elements-to-10-000-deleted-10-000-inserted-and-2-000-shuffled' class='heading'>- From 100,000 elements to 10,000 deleted, 10,000 inserted and 2,000 shuffled</h4>
<table><thead>
<tr>
<th style="text-align: left"></th>
<th style="text-align: right">Time(sec)</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">DifferenceKit</td>
<td style="text-align: right"><code>0.0348</code></td>
</tr>
<tr>
<td style="text-align: left">RxDataSources</td>
<td style="text-align: right"><code>0.1024</code></td>
</tr>
<tr>
<td style="text-align: left">IGListKit</td>
<td style="text-align: right"><code>0.7002</code></td>
</tr>
<tr>
<td style="text-align: left">FlexibleDiff</td>
<td style="text-align: right"><code>0.2189</code></td>
</tr>
<tr>
<td style="text-align: left">DeepDiff</td>
<td style="text-align: right"><code>0.5537</code></td>
</tr>
<tr>
<td style="text-align: left">Differ</td>
<td style="text-align: right"><code>153.8007</code></td>
</tr>
<tr>
<td style="text-align: left">Dwifft</td>
<td style="text-align: right"><code>187.1341</code></td>
</tr>
<tr>
<td style="text-align: left">Swift.CollectionDifference</td>
<td style="text-align: right"><code>5.0281</code></td>
</tr>
</tbody></table>
<h3 id='features-comparison' class='heading'>Features Comparison</h3>
<h4 id='algorithm' class='heading'>- Algorithm</h4>
<table><thead>
<tr>
<th style="text-align: left"></th>
<th style="text-align: right">Base algorithm</th>
<th style="text-align: right">Order</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">DifferenceKit</td>
<td style="text-align: right">Heckel</td>
<td style="text-align: right">O(N)</td>
</tr>
<tr>
<td style="text-align: left">RxDataSources</td>
<td style="text-align: right">Heckel</td>
<td style="text-align: right">O(N)</td>
</tr>
<tr>
<td style="text-align: left">FlexibleDiff</td>
<td style="text-align: right">Heckel</td>
<td style="text-align: right">O(N)</td>
</tr>
<tr>
<td style="text-align: left">IGListKit</td>
<td style="text-align: right">Heckel</td>
<td style="text-align: right">O(N)</td>
</tr>
<tr>
<td style="text-align: left">DeepDiff</td>
<td style="text-align: right">Heckel</td>
<td style="text-align: right">O(N)</td>
</tr>
<tr>
<td style="text-align: left">Differ</td>
<td style="text-align: right">Myers</td>
<td style="text-align: right">O(ND)</td>
</tr>
<tr>
<td style="text-align: left">Dwifft</td>
<td style="text-align: right">Myers</td>
<td style="text-align: right">O(ND)</td>
</tr>
<tr>
<td style="text-align: left">Swift.CollectionDifference</td>
<td style="text-align: right">Myers</td>
<td style="text-align: right">O(ND)</td>
</tr>
</tbody></table>
<p>* <a href="https://dl.acm.org/citation.cfm?id=359467"><strong>Heckel algorithm</strong></a><br>
* <a href="http://www.xmailserver.org/diff2.pdf"><strong>Myers algorithm</strong></a> </p>
<h4 id='supported-collection' class='heading'>- Supported Collection</h4>
<table><thead>
<tr>
<th style="text-align: left"></th>
<th style="text-align: center">Linear</th>
<th style="text-align: center">Sectioned</th>
<th style="text-align: center">Duplicate element/section</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">DifferenceKit</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">RxDataSources</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">FlexibleDiff</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">IGListKit</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">DeepDiff</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">Differ</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">Dwifft</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">Swift.CollectionDifference</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">✅</td>
</tr>
</tbody></table>
<p>* <strong>Linear</strong> means 1-dimensional collection<br>
* <strong>Sectioned</strong> means 2-dimensional collection </p>
<h4 id='supported-element-diff' class='heading'>- Supported Element Diff</h4>
<table><thead>
<tr>
<th style="text-align: left"></th>
<th style="text-align: center">Delete</th>
<th style="text-align: center">Insert</th>
<th style="text-align: center">Move</th>
<th style="text-align: center">Reload</th>
<th style="text-align: center">Move across sections</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">DifferenceKit</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">RxDataSources</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">FlexibleDiff</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">IGListKit</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">DeepDiff</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">Differ</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">Dwifft</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">Swift.CollectionDifference</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
</tr>
</tbody></table>
<h4 id='supported-section-diff' class='heading'>- Supported Section Diff</h4>
<table><thead>
<tr>
<th style="text-align: left"></th>
<th style="text-align: center">Delete</th>
<th style="text-align: center">Insert</th>
<th style="text-align: center">Move</th>
<th style="text-align: center">Reload</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">DifferenceKit</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">RxDataSources</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">FlexibleDiff</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
</tr>
<tr>
<td style="text-align: left">IGListKit</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">DeepDiff</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">Differ</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">Dwifft</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">✅</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
</tr>
<tr>
<td style="text-align: left">Swift.CollectionDifference</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
<td style="text-align: center">❌</td>
</tr>
</tbody></table>
<hr>
<h2 id='requirements' class='heading'>Requirements</h2>
<ul>
<li>Swift 4.2+</li>
<li>iOS 9.0+</li>
<li>tvOS 9.0+</li>
<li>OS X 10.9+</li>
<li>watchOS 2.0+ (only algorithm)</li>
</ul>
<hr>
<h2 id='installation' class='heading'>Installation</h2>
<h3 id='a-href-https-cocoapods-org-cocoapods-a' class='heading'><a href="https://cocoapods.org/">CocoaPods</a></h3>
<p>To use only algorithm without extensions for UI, add the following to your <code>Podfile</code>:</p>
<pre class="highlight ruby"><code><span class="n">pod</span> <span class="s1">'DifferenceKit/Core'</span>
</code></pre>
<h4 id='ios-tvos' class='heading'>iOS / tvOS</h4>
<p>To use DifferenceKit with UIKit extension, add the following to your <code>Podfile</code>:</p>
<pre class="highlight ruby"><code><span class="n">pod</span> <span class="s1">'DifferenceKit'</span>
</code></pre>
<p>or</p>
<pre class="highlight ruby"><code><span class="n">pod</span> <span class="s1">'DifferenceKit/UIKitExtension'</span>
</code></pre>
<h4 id='macos' class='heading'>macOS</h4>
<p>To use DifferenceKit with AppKit extension, add the following to your <code>Podfile</code>:</p>
<pre class="highlight ruby"><code><span class="n">pod</span> <span class="s1">'DifferenceKit/AppKitExtension'</span>
</code></pre>
<h4 id='watchos' class='heading'>watchOS</h4>
<p>There is no UI extension for watchOS.<br>
To use only algorithm without extensions for UI, add the following to your <code>Podfile</code>:</p>
<pre class="highlight ruby"><code><span class="n">pod</span> <span class="s1">'DifferenceKit/Core'</span>
</code></pre>
<h3 id='a-href-https-github-com-carthage-carthage-carthage-a' class='heading'><a href="https://github.com/Carthage/Carthage">Carthage</a></h3>
<p>Add the following to your <code>Cartfile</code>:</p>
<pre class="highlight ruby"><code><span class="n">github</span> <span class="s2">"ra1028/DifferenceKit"</span>
</code></pre>
<h3 id='a-href-https-developer-apple-com-documentation-xcode-adding_package_dependencies_to_your_app-swift-package-manager-for-apple-platforms-a' class='heading'><a href="https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app">Swift Package Manager for Apple platforms</a></h3>
<p>Select Xcode menu <code>File > Swift Packages > Add Package Dependency</code> and enter repository URL with GUI. </p>
<pre class="highlight plaintext"><code>Repository: https://github.com/ra1028/DifferenceKit
</code></pre>
<h3 id='a-href-https-swift-org-package-manager-swift-package-manager-a' class='heading'><a href="https://swift.org/package-manager/">Swift Package Manager</a></h3>
<p>Add the following to the dependencies of your <code>Package.swift</code>:</p>
<pre class="highlight swift"><code><span class="o">.</span><span class="nf">package</span><span class="p">(</span><span class="nv">url</span><span class="p">:</span> <span class="s">"https://github.com/ra1028/DifferenceKit.git"</span><span class="p">,</span> <span class="nv">from</span><span class="p">:</span> <span class="s">"version"</span><span class="p">)</span>
</code></pre>
<hr>
<h2 id='contribution' class='heading'>Contribution</h2>
<p>Pull requests, bug reports and feature requests are welcome 🚀<br>
Please see the <a href="https://github.com/ra1028/DifferenceKit/blob/master/CONTRIBUTING.md">CONTRIBUTING</a> file for learn how to contribute to DifferenceKit. </p>
<hr>
<h2 id='credit' class='heading'>Credit</h2>
<h4 id='bibliography' class='heading'>Bibliography</h4>
<p>DifferenceKit was developed with reference to the following excellent materials and framework. </p>
<ul>
<li><a href="https://dl.acm.org/citation.cfm?id=359467">A technique for isolating differences between files</a> (by <a href="https://dl.acm.org/author_page.cfm?id=81100051772">Paul Heckel</a>)</li>
<li><a href="https://github.com/horita-yuya/DifferenceAlgorithmComparison">DifferenceAlgorithmComparison</a> (by <a href="https://github.com/horita-yuya">@horita-yuya</a>)</li>
</ul>
<h4 id='oss-using-differencekit' class='heading'>OSS using DifferenceKit</h4>
<p>The list of the awesome OSS which uses this library. They also help to understanding how to use DifferenceKit. </p>
<ul>
<li><a href="https://github.com/ra1028/Carbon">Carbon</a> (by <a href="https://github.com/ra1028">@ra1028</a>)</li>
<li><a href="https://github.com/ra1028/DiffableDataSources">DiffableDataSources</a> (by <a href="https://github.com/ra1028">@ra1028</a>)</li>
<li><a href="https://github.com/RocketChat/Rocket.Chat.iOS">Rocket.Chat.iOS</a> (by <a href="https://github.com/RocketChat">RocketChat</a>)</li>
<li><a href="https://github.com/wireapp/wire-ios">wire-ios</a> (by <a href="https://github.com/wireapp">Wire Swiss GmbH</a>)</li>
<li><a href="https://github.com/plangrid/ReactiveLists">ReactiveLists</a> (by <a href="https://github.com/plangrid">PlanGrid</a>)</li>
<li><a href="https://github.com/cardoso/ReduxMovieDB">ReduxMovieDB</a> (by <a href="https://github.com/cardoso">@cardoso</a>)</li>
<li><a href="https://github.com/skagedal/TetrisDiffingCompetition">TetrisDiffingCompetition</a> (by <a href="https://github.com/skagedal">@skagedal</a>)</li>
</ul>
<h4 id='other-diffing-libraries' class='heading'>Other diffing libraries</h4>
<p>I respect and ️❤️ all libraries involved in diffing. </p>
<ul>
<li><a href="https://github.com/RxSwiftCommunity/RxDataSources">RxDataSources</a> (by <a href="https://github.com/kzaher">@kzaher</a>, <a href="https://github.com/RxSwiftCommunity">RxSwift Community</a>)</li>
<li><a href="https://github.com/Instagram/IGListKit">IGListKit</a> (by <a href="https://github.com/Instagram">Instagram</a>)</li>
<li><a href="https://github.com/RACCommunity/FlexibleDiff">FlexibleDiff</a> (by <a href="https://github.com/andersio">@andersio</a>, <a href="https://github.com/RACCommunity">RACCommunity</a>)</li>
<li><a href="https://github.com/onmyway133/DeepDiff">DeepDiff</a> (by <a href="https://github.com/onmyway133">@onmyway133</a>)</li>
<li><a href="https://github.com/tonyarnold/Differ">Differ</a> (by <a href="https://github.com/tonyarnold">@tonyarnold</a>)</li>
<li><a href="https://github.com/jflinter/Dwifft">Dwifft</a> (by <a href="https://github.com/jflinter">@jflinter</a>)</li>
<li><a href="https://github.com/osteslag/Changeset">Changeset</a> (by <a href="https://github.com/osteslag">@osteslag</a>)</li>
</ul>
<hr>
<h2 id='license' class='heading'>License</h2>
<p>DifferenceKit is released under the <a href="https://github.com/ra1028/DifferenceKit/blob/master/LICENSE">Apache 2.0 License</a>.</p>
</div>
</section>
</article>
</div>
<section class="footer">
<p>© 2019 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2019-10-21)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.11.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
</div>
</html>