IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
LexicographicListComparer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
5{
6
11 internal class LexicographicListComparer<T> : LexicographicListComparer<T, IComparer<T>>
12 {
13
17 public new static readonly LexicographicListComparer<T> Default = new LexicographicListComparer<T>(Comparer<T>.Default);
18
23 public LexicographicListComparer(IComparer<T> comparer) :
24 base(comparer)
25 {
26
27 }
28
29 }
30
36 internal class LexicographicListComparer<T, TComparer> : LexicographicListComparer<T, IComparer<T>, IReadOnlyList<T>>
37 {
38
43
48 public LexicographicListComparer(IComparer<T> comparer) :
49 base(comparer)
50 {
51
52 }
53
54 }
55
62 class LexicographicListComparer<T, TComparer, TList> : Comparer<TList>
63 where TComparer : IComparer<T>
64 where TList : IReadOnlyList<T>
65 {
66
67 readonly TComparer _comparer;
68
73 public LexicographicListComparer(TComparer comparer)
74 {
75 _comparer = comparer;
76 }
77
79 public override int Compare(TList? x, TList? y)
80 {
81 if (x == null && y is null)
82 return 0;
83
84 if (x == null)
85 return +1;
86
87 if (y == null)
88 return -1;
89
90 int c = x.Count.CompareTo(y.Count);
91 if (c != 0)
92 return c;
93
94 var length = Math.Min(x.Count, y.Count);
95 for (int i = 0; i < length; i++)
96 {
97 c = _comparer.Compare(x[i], y[i]);
98 if (c != 0)
99 return c;
100 }
101
102 return 0;
103 }
104
105 }
106
107}
Implements an IComparer<T> which lexicographically compares a two lists.
LexicographicListComparer(IComparer< T > comparer)
Initializes a new instance.
LexicographicListComparer(TComparer comparer)
Initializes a new instance.
static new readonly LexicographicListComparer< T > Default
Returns a default LexicographicListComparer<T> instance.