Reverse comparer shenanigans

This commit is contained in:
wrenge 2024-11-12 16:37:39 +03:00
parent c989276f5e
commit b6a1a81fdc
1 changed files with 17 additions and 2 deletions

View File

@ -25,14 +25,29 @@ namespace DotRecast.Core.Collections
{ {
public class RcSortedQueue<T> public class RcSortedQueue<T>
{ {
private sealed class ReverseComparer : IComparer<T>
{
private readonly Comparison<T> _comparison;
public ReverseComparer(Comparison<T> comparison)
{
_comparison = comparison;
}
public int Compare(T x, T y)
{
return _comparison(x, y) * -1;
}
}
private bool _dirty; private bool _dirty;
private readonly List<T> _items; private readonly List<T> _items;
private readonly Comparer<T> _comparer; private readonly IComparer<T> _comparer;
public RcSortedQueue(Comparison<T> comp) public RcSortedQueue(Comparison<T> comp)
{ {
_items = new List<T>(); _items = new List<T>();
_comparer = Comparer<T>.Create((x, y) => comp.Invoke(x, y) * -1); _comparer = new ReverseComparer(comp);
} }
public int Count() public int Count()