move ReverseComparer to spark_core
This commit is contained in:
1 parent
8ba1c7a602
commit
ff33d0d735
3 files changed
+18
-21
No files matched your search
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.utils {
|
||||
public class ReverseComparer<T> : IComparer<T> {
|
||||
private readonly IComparer<T> _wrapped;
|
||||
|
||||
public ReverseComparer(IComparer<T> wrapped) {
|
||||
_wrapped = wrapped;
|
||||
}
|
||||
|
||||
public int Compare(T x, T y) {
|
||||
// reverse operands
|
||||
return _wrapped.Compare(y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ namespace bts.utils {
|
||||
Comparer<T?>.Create(nullable_comparison<T>(comparer.Compare));
|
||||
|
||||
public static IComparer<T> reverse<T>(this IComparer<T> comparer) =>
|
||||
Comparer<T>.Create((a, b) => comparer.Compare(b, a));
|
||||
new ReverseComparer<T>(comparer);
|
||||
|
||||
class NonGenericComparerWrapper<T> : IComparer {
|
||||
readonly IComparer<T> _comparer;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace bts.utils {
|
||||
public class ReverseComparer<T> : IComparer<T> {
|
||||
public static readonly IComparer<T> Default =
|
||||
new ReverseComparer<T>(Comparer<T>.Default);
|
||||
|
||||
readonly IComparer<T> _wrapped;
|
||||
|
||||
public ReverseComparer(IComparer<T> wrapped) =>
|
||||
_wrapped = wrapped;
|
||||
|
||||
public int Compare(T x, T y) =>
|
||||
// reverse operands
|
||||
_wrapped.Compare(y, x);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user