forked from mirror/DotRecast
Pass delegate
This commit is contained in:
parent
2397f23fc3
commit
fff0998613
|
@ -25,29 +25,14 @@ 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 IComparer<T> _comparer;
|
private readonly Comparison<T> _comparison;
|
||||||
|
|
||||||
public RcSortedQueue(Comparison<T> comp)
|
public RcSortedQueue(Comparison<T> comp)
|
||||||
{
|
{
|
||||||
_items = new List<T>();
|
_items = new List<T>();
|
||||||
_comparer = new ReverseComparer(comp);
|
_comparison = (x, y) => comp(x, y) * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count()
|
public int Count()
|
||||||
|
@ -70,7 +55,7 @@ namespace DotRecast.Core.Collections
|
||||||
{
|
{
|
||||||
if (_dirty)
|
if (_dirty)
|
||||||
{
|
{
|
||||||
_items.Sort(_comparer); // reverse
|
_items.Sort(_comparison); // reverse
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue