IPriorityQueue.cs 2.1 KB

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