![]() |
VOOZH | about |
dotnet add package spkl.Diffs --version 2.1.0
NuGet\Install-Package spkl.Diffs -Version 2.1.0
<PackageReference Include="spkl.Diffs" Version="2.1.0" />
<PackageVersion Include="spkl.Diffs" Version="2.1.0" />Directory.Packages.props
<PackageReference Include="spkl.Diffs" />Project file
paket add spkl.Diffs --version 2.1.0
#r "nuget: spkl.Diffs, 2.1.0"
#:package spkl.Diffs@2.1.0
#addin nuget:?package=spkl.Diffs&version=2.1.0Install as a Cake Addin
#tool nuget:?package=spkl.Diffs&version=2.1.0Install as a Cake Tool
Provides a .NET implementation to the diff algorithm (shortest edit script) described by Eugene Myers in "An O(ND) Difference Algorithm and Its Variations". Unlike some other implementations, this one can compare sequences of any object type, using the standard Equals method or a custom IEqualityComparer.
In this example, we will diff two string sequences:
0 1 2 3 4 5 6 (These are the indexes)
A: a b c a b b a
B: c b a b a c
To do this, we use the following code:
// using spkl.Diffs;
string[] a = new[] { "a", "b", "c", "a", "b", "b", "a" };
string[] b = new[] { "c", "b", "a", "b", "a", "c" };
MyersDiff<string> diff = new MyersDiff<string>(a, b);
Using generic typing, you can diff all sorts of types. You can also customize which values are considered equal by specifying a third constructor parameter (IEqualityComparer<T>).
There are two methods to access the results: GetEditScript() and GetResult().
GetEditScript() returns a sequence of edit instructions. You can understand these as instructions to follow to transform sequence A to sequence B. Every instruction contains four integers, a starting line number in A and B and the number of lines to add or remove. In this case, the return value would look like this:
| LineA | LineB | CountA | CountB |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 2 | 2 | 1 | 0 |
| 5 | 4 | 1 | 0 |
| 7 | 5 | 0 | 1 |
To better understand this, let's follow these instructions:
In A, starting at line 0 (LineA), remove 1 line (CountA). From B, starting at line 0 (LineB), add 1 line (CountB) at position 0 (LineA). (This removes the first "a" and adds the first "c")
In A, starting at line 2, remove 1 line. (This removes the "c")
In A, starting at line 5, remove 1 line. (This removes the last "b")
From B, starting at line 5 (LineB), add 1 line (CountB) at position 7 (LineA). (This adds the last "c")
Following these instructions, abcabba is transformed to cbabac.
GetResult() returns the resulting diff as a sequence of tuples that represent lines. In this case, the return value would look like this:
| ResultType | AItem | BItem |
|---|---|---|
| A | a | |
| B | c | |
| Both | b | b |
| A | c | |
| Both | a | a |
| Both | b | b |
| A | b | |
| Both | a | a |
| B | c |
This is similar to how the result would be displayed in a visual comparison application. The AItem and BItem columns contain sequence A and B, respectively. The ResultType column shows whether a line contains a value from sequence A, B, or from both. You can see which values were matched with each other.
You can specify the order in which you want unmatched lines to appear by using the GetResult(ResultOrder) overload. To visualize this, we need to use a new example.
A: a b c
B: x y
The following table shows how the result would be returned when specifying the different ResultOrder values AABB, BBAA, ABAB and BABA:
| AABB | BBAA | ABAB | BABA |
|---|---|---|---|
| a - | - x | a - | - x |
| b - | - y | - x | a - |
| c - | a - | b - | - y |
| - x | b - | - y | b - |
| - y | c - | c - | c - |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on spkl.Diffs:
| Package | Downloads |
|---|---|
|
VertiGIS.Mobile
Create VertiGIS Mobile apps for Android, iOS, and UWP. Extend your apps with custom components, operations and services. |
|
|
GitDotNet
Package Description |
This package is not used by any popular GitHub repositories.
- Provided snupkg for debug symbols.