DtNodeQueue.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
  3. recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
  4. DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
  5. This software is provided 'as-is', without any express or implied
  6. warranty. In no event will the authors be held liable for any damages
  7. arising from the use of this software.
  8. Permission is granted to anyone to use this software for any purpose,
  9. including commercial applications, and to alter it and redistribute it
  10. freely, subject to the following restrictions:
  11. 1. The origin of this software must not be misrepresented; you must not
  12. claim that you wrote the original software. If you use this software
  13. in a product, an acknowledgment in the product documentation would be
  14. appreciated but is not required.
  15. 2. Altered source versions must be plainly marked as such, and must not be
  16. misrepresented as being the original software.
  17. 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. using DotRecast.Core;
  20. namespace DotRecast.Detour
  21. {
  22. public class DtNodeQueue
  23. {
  24. private readonly RcSortedQueue<DtNode> m_heap = new RcSortedQueue<DtNode>((n1, n2) => n1.total.CompareTo(n2.total));
  25. public int Count()
  26. {
  27. return m_heap.Count();
  28. }
  29. public void Clear()
  30. {
  31. m_heap.Clear();
  32. }
  33. public DtNode Peek()
  34. {
  35. return m_heap.Peek();
  36. }
  37. public DtNode Pop()
  38. {
  39. var node = Peek();
  40. m_heap.Remove(node);
  41. return node;
  42. }
  43. public void Push(DtNode node)
  44. {
  45. m_heap.Enqueue(node);
  46. }
  47. public void Modify(DtNode node)
  48. {
  49. m_heap.Remove(node);
  50. Push(node);
  51. }
  52. public bool IsEmpty()
  53. {
  54. return 0 == m_heap.Count();
  55. }
  56. }
  57. }