IPriorityQueue.cs 2.0 KB

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