support ToList() at RcSortedQueue

This commit is contained in:
ikpil 2023-09-06 12:17:38 +09:00
parent ecca198d6f
commit 8b4a280958
2 changed files with 17 additions and 5 deletions

View File

@ -45,20 +45,24 @@ namespace DotRecast.Core
_items.Clear(); _items.Clear();
} }
public T Top() private void Balance()
{ {
if (_dirty) if (_dirty)
{ {
_items.Sort(_comparison); // reverse _items.Sort(_comparison); // reverse
_dirty = false; _dirty = false;
} }
}
public T Peek()
{
Balance();
return _items[_items.Count - 1]; return _items[_items.Count - 1];
} }
public T Dequeue() public T Dequeue()
{ {
var node = Top(); var node = Peek();
_items.Remove(node); _items.Remove(node);
return node; return node;
} }
@ -82,5 +86,13 @@ namespace DotRecast.Core
{ {
return 0 == _items.Count; return 0 == _items.Count;
} }
public List<T> ToList()
{
Balance();
var temp = new List<T>(_items);
temp.Reverse();
return temp;
}
} }
} }

View File

@ -36,14 +36,14 @@ namespace DotRecast.Detour
m_heap.Clear(); m_heap.Clear();
} }
public DtNode Top() public DtNode Peek()
{ {
return m_heap.Top(); return m_heap.Peek();
} }
public DtNode Pop() public DtNode Pop()
{ {
var node = Top(); var node = Peek();
m_heap.Remove(node); m_heap.Remove(node);
return node; return node;
} }