-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComparers.cs
51 lines (44 loc) · 1.14 KB
/
Comparers.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
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
namespace LCS
{
readonly struct StringOverlapComparer : IComparer<String>
{
public int Compare(String x, String y)
{
if (x.End <= y.Start) return -1;
if (y.End <= x.Start) return +1;
return 0;
}
}
readonly struct LengthStartIndexComparer : IComparer<int>
{
readonly String[] Strings;
public LengthStartIndexComparer(String[] strings)
{
Strings = strings ?? throw new ArgumentNullException(nameof(strings));
}
public readonly int Compare(int i, int j)
{
int c;
if ((c = Strings[j].Length - Strings[i].Length) != 0) return c;
if ((c = Strings[i].Start - Strings[j].Start ) != 0) return c;
return i - j;
}
}
readonly struct StartLengthIndexComparer : IComparer<int>
{
public readonly String[] Strings;
public StartLengthIndexComparer(String[] strings)
{
Strings = strings ?? throw new ArgumentNullException(nameof(strings));
}
public readonly int Compare(int i, int j)
{
int c;
if ((c = Strings[i].Start - Strings[j].Start ) != 0) return c;
if ((c = Strings[j].Length - Strings[i].Length) != 0) return c;
return i - j;
}
}
}