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();
}
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<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();
}
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;
}