From 8b4a2809589a50f053d6b13101ca3a88c60210cb Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 6 Sep 2023 12:17:38 +0900 Subject: [PATCH] support ToList() at RcSortedQueue --- src/DotRecast.Core/RcSortedQueue.cs | 16 ++++++++++++++-- src/DotRecast.Detour/DtNodeQueue.cs | 6 +++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/DotRecast.Core/RcSortedQueue.cs b/src/DotRecast.Core/RcSortedQueue.cs index 03c9960..e8918c1 100644 --- a/src/DotRecast.Core/RcSortedQueue.cs +++ b/src/DotRecast.Core/RcSortedQueue.cs @@ -45,20 +45,24 @@ namespace DotRecast.Core _items.Clear(); } - public T Top() + private void Balance() { if (_dirty) { _items.Sort(_comparison); // reverse _dirty = false; } + } + public T Peek() + { + Balance(); return _items[_items.Count - 1]; } public T Dequeue() { - var node = Top(); + var node = Peek(); _items.Remove(node); return node; } @@ -82,5 +86,13 @@ namespace DotRecast.Core { return 0 == _items.Count; } + + public List ToList() + { + Balance(); + var temp = new List(_items); + temp.Reverse(); + return temp; + } } } \ No newline at end of file diff --git a/src/DotRecast.Detour/DtNodeQueue.cs b/src/DotRecast.Detour/DtNodeQueue.cs index 8fb399b..5e8368f 100644 --- a/src/DotRecast.Detour/DtNodeQueue.cs +++ b/src/DotRecast.Detour/DtNodeQueue.cs @@ -36,14 +36,14 @@ namespace DotRecast.Detour m_heap.Clear(); } - public DtNode Top() + public DtNode Peek() { - return m_heap.Top(); + return m_heap.Peek(); } public DtNode Pop() { - var node = Top(); + var node = Peek(); m_heap.Remove(node); return node; }