Skip to main content

Priority

Trait Priority 

Source
pub trait Priority {
    // Required method
    fn compare(&self, other: &Self) -> Ordering;

    // Provided method
    fn compare_new(&self, old: &Self) -> Ordering { ... }
}
Expand description

Trait used by PriorityQueue to determine the order by which nodes should be enqueued.

Required Methods§

Source

fn compare(&self, other: &Self) -> Ordering

Compare a (possibly new) priority to an already queued one.

The meaning for the results is as follows:

  • Less: Lower priority (i.e. should place after other)
  • Equal: Same priority - same priority; can be placed before or after other
  • Greater: Higher priority - Higher priority

This must be transitive.

Provided Methods§

Source

fn compare_new(&self, old: &Self) -> Ordering

Compare a new (not in a queue) priority with an already queued one (old).

PriorityQueue implementers must always use this function when enqueueing or re-queueing an entry to compare it with existing ones.

This does not need to be transitive (and often shouldn’t be).

This must return the same as compare if the result of compare isn’t Ordering::Equal.

§Example (logic used in FIFO):
fn compare_new(&self, old: &Self) -> Ordering {
    // If priority is Equal, then return Less (as `old` was queued first)
    self.0.compare(&old.0).then(Ordering::Less)
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<O: Ord> Priority for LowestFirst<O>

Source§

impl<O: Ord> Priority for O

Source§

impl<P: Priority> Priority for MutexWaiter<P>

Has the same Priority impl as P with the exception of pinning holding entry to head.

Source§

impl<P: Priority> Priority for SemaphoreWaiter<P>

Has the same priority as P except “held” entries always have higher priority than pending requesters

Additionally constraints order with the same priority to enqueue the lowest request count first to minimize waiting (this applies after the inner priority has compared, so FIFO and LIFO will prevent this).

Source§

impl<P: Priority> Priority for FIFO<P>

Source§

impl<P: Priority> Priority for LIFO<P>