pub struct Queue<T, P: Eq + PartialEq + Ord> { /* private fields */ }
Expand description
A priority queue that stores arbitrary data sorted by time
Items of type T
are stored in order by f64
time and called Plan<T>
.
Plans can have priorities given by some specified orderable type P
.
When plans are created they are sequentially assigned a PlanId
that is a
wrapped u64
. If two plans are scheduled for the same time then the plan
with the lowest priority is placed earlier. If two plans have the same time
and priority then the plan that is scheduled first (i.e., that has the
lowest id) is placed earlier.
The time, plan id, and priority are stored in a binary heap of Entry<P>
objects. The data payload of the event is stored in a hash map by plan id.
Plan cancellation occurs by removing the corresponding entry from the data
hash map.
Implementations§
Source§impl<T, P: Eq + PartialEq + Ord> Queue<T, P>
impl<T, P: Eq + PartialEq + Ord> Queue<T, P>
Sourcepub fn add_plan(&mut self, time: f64, data: T, priority: P) -> PlanId
pub fn add_plan(&mut self, time: f64, data: T, priority: P) -> PlanId
Add a plan to the queue at the specified time
Returns a PlanId
for the newly-added plan that can be used to cancel it
if needed.
Sourcepub fn cancel_plan(&mut self, plan_id: &PlanId) -> Option<T>
pub fn cancel_plan(&mut self, plan_id: &PlanId) -> Option<T>
Cancel a plan that has been added to the queue
pub fn is_empty(&self) -> bool
pub fn next_time(&self) -> Option<f64>
Sourcepub fn get_next_plan(&mut self) -> Option<Plan<T>>
pub fn get_next_plan(&mut self) -> Option<Plan<T>>
Retrieve the earliest plan in the queue
Returns the next plan if it exists or else None
if the queue is empty
Sourcepub fn list_schedules(&self, at_most: usize) -> Vec<&PlanSchedule<P>>
pub fn list_schedules(&self, at_most: usize) -> Vec<&PlanSchedule<P>>
Returns a list of length at_most
, or unbounded if at_most=0
, of active scheduled
PlanSchedule
s ordered as they are in the queue itself.