From b6a1a81fdc2f37a4c265f6a5da854c0ac5da5421 Mon Sep 17 00:00:00 2001 From: wrenge Date: Tue, 12 Nov 2024 16:37:39 +0300 Subject: [PATCH] Reverse comparer shenanigans --- .../Collections/RcSortedQueue.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/DotRecast.Core/Collections/RcSortedQueue.cs b/src/DotRecast.Core/Collections/RcSortedQueue.cs index 0c06aad..f5c817e 100644 --- a/src/DotRecast.Core/Collections/RcSortedQueue.cs +++ b/src/DotRecast.Core/Collections/RcSortedQueue.cs @@ -25,14 +25,29 @@ namespace DotRecast.Core.Collections { public class RcSortedQueue { + private sealed class ReverseComparer : IComparer + { + private readonly Comparison _comparison; + + public ReverseComparer(Comparison comparison) + { + _comparison = comparison; + } + + public int Compare(T x, T y) + { + return _comparison(x, y) * -1; + } + } + private bool _dirty; private readonly List _items; - private readonly Comparer _comparer; + private readonly IComparer _comparer; public RcSortedQueue(Comparison comp) { _items = new List(); - _comparer = Comparer.Create((x, y) => comp.Invoke(x, y) * -1); + _comparer = new ReverseComparer(comp); } public int Count()