IPriorityQueue.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. namespace Priority_Queue
  6. {
  7. /// <summary>
  8. /// Credit: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp
  9. /// The IPriorityQueue interface. This is mainly here for purists, and in case I decide to add more implementations later.
  10. /// For speed purposes, it is actually recommended that you *don't* access the priority queue through this interface, since the JIT can
  11. /// (theoretically?) optimize method calls from concrete-types slightly better.
  12. /// </summary>
  13. public interface IPriorityQueue<TItem, in TPriority> : IEnumerable<TItem>
  14. where TPriority : IComparable<TPriority>
  15. {
  16. /// <summary>
  17. /// Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out.
  18. /// See implementation for how duplicates are handled.
  19. /// </summary>
  20. void Enqueue(TItem node, TPriority priority);
  21. /// <summary>
  22. /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it.
  23. /// </summary>
  24. bool TryDequeue(out TItem item);
  25. /// <summary>
  26. /// Removes every node from the queue.
  27. /// </summary>
  28. void Clear();
  29. /// <summary>
  30. /// Returns whether the given node is in the queue.
  31. /// </summary>
  32. bool Contains(TItem node);
  33. /// <summary>
  34. /// Removes a node from the queue. The node does not need to be the head of the queue.
  35. /// </summary>
  36. void Remove(TItem node);
  37. /// <summary>
  38. /// Call this method to change the priority of a node.
  39. /// </summary>
  40. void UpdatePriority(TItem node, TPriority priority);
  41. /// <summary>
  42. /// Returns the head of the queue, without removing it (use Dequeue() for that).
  43. /// </summary>
  44. TItem First { get; }
  45. /// <summary>
  46. /// Returns the number of nodes in the queue.
  47. /// </summary>
  48. int Count { get; }
  49. }
  50. }