spkl.Diffs
2.0.1
See the version list below for details.
dotnet add package spkl.Diffs --version 2.0.1
NuGet\Install-Package spkl.Diffs -Version 2.0.1
<PackageReference Include="spkl.Diffs" Version="2.0.1" />
paket add spkl.Diffs --version 2.0.1
#r "nuget: spkl.Diffs, 2.0.1"
// Install spkl.Diffs as a Cake Addin #addin nuget:?package=spkl.Diffs&version=2.0.1 // Install spkl.Diffs as a Cake Tool #tool nuget:?package=spkl.Diffs&version=2.0.1
Diffs
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.
! Looking for support of .NET Framework 4.x or .NET Standard 2.0? Use release 1.x.
Example Usage
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()
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()
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.
GetResult(ResultOrder)
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 | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
- Upgraded target framework to .NET 8.0. Older frameworks are still supported with versions 1.x.
- Removed the ArrayView class.
- Fixed table formatting in README (2.0.1).