-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatienceDiffCorrelater.cs
38 lines (33 loc) · 1.65 KB
/
PatienceDiffCorrelater.cs
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
using IEnumerableCorrelater.CorrelaterWrappers;
using IEnumerableCorrelater.Exceptions;
using IEnumerableCorrelater.Interfaces;
using System;
using System.Threading;
namespace IEnumerableCorrelater.Correlaters
{
/// <summary>
/// PatienceDiffCorrelater is an algorithm that was developed specifically for comparing diffs in code.
/// It does a very good job at creating human-readable diffs.
/// </summary>
public class PatienceDiffCorrelater<T> : AbstractCorrelater<T>, IContinuousCorrelater<T>
{
private readonly IContinuousCorrelater<T> innerCorrelater =
new IgnoreIdenticalBeginningAndEndCorrelaterWrapper<T>(
new SplitByPatienceAlgorithmWrapper<T>(
new IgnoreIdenticalBeginningAndEndCorrelaterWrapper<T>(
new MyersAlgorithmCorrelater<T>())));
public PatienceDiffCorrelater()
{
if (default(T) != null && typeof(T) != typeof(char))
throw new EnumerableCorrelaterException($"{nameof(T)} must be nullable or a char");
innerCorrelater.OnProgressUpdate += (p, t) => OnProgressUpdate?.Invoke(p, t);
innerCorrelater.OnResultUpdate += r => OnResultUpdate?.Invoke(r);
}
public override event Action<int, int> OnProgressUpdate;
public event Action<CorrelaterResult<T>> OnResultUpdate;
protected override CorrelaterResult<T> InternalCorrelate(ICollectionWrapper<T> collection1, ICollectionWrapper<T> collection2, CancellationToken cancellationToken = default)
{
return innerCorrelater.Correlate(collection1, collection2, cancellationToken);
}
}
}