[][src]Struct topq::Topq

pub struct Topq<D, P, T, N> where
    D: 'static,
    P: Ord,
    T: Timer,
    N: ArrayLength<TopqItem<D, P, T>>, 
{ /* fields omitted */ }

A "Timeout Priority Queue"

This is generic over four parameters:

  • D: The data type held by the priority queue
  • P: The priority type. Must implement Ord
  • T: The timer type. Must implement topq::Timer
  • N: The number of priority levels that can be kept at once

Note

Topq CAN handle timers that rollover periodically, however Topq::purge() MUST be called AT LEAST twice per rollover time period.

For example, when using a 32.768kHz clock source and a u32 time value, the timer will roll over every 1.51 days or so. In this case, you MUST call purge to remove stale values at least every 0.75 days or so.

Implementations

impl<D, P, T, N> Topq<D, P, T, N> where
    D: 'static,
    P: Ord,
    T: Timer,
    N: ArrayLength<TopqItem<D, P, T>>, 
[src]

pub fn new(timer: T) -> Self[src]

Create an empty Topq with the given timer

pub fn now(&self) -> T::Time[src]

Get the current time based on the internal counter

pub fn insert(&mut self, item: D, prio: P, valid_for: T::Time)[src]

Insert a datapoint into the priority queue

If the queue already contains an item with the same priority, the old data and timeout will be replaced. If the queue does not contain an item at this priority, it will be inserted if there is room or it is a higher priority than the existing items

pub fn prune(&mut self)[src]

Remove any expired items from the priority queue

See the module level documentation for when it is necessary to call this function

pub fn get_data(&self) -> Option<&D>[src]

Obtain the highest priority and currently valid data, if any

This is typically used when you ONLY need the current value, and not the remaining validity time or the priority of the currently valid data

pub fn get_item(&self) -> Option<&TopqItem<D, P, T>>[src]

Obtain the highest priority and currently valid topq item, if any

This is typically used when you need the current value, AND ALSO need the remaining validity time or the priority of the currently valid data

Trait Implementations

impl<'a, D, P, T, N> IntoIterator for &'a Topq<D, P, T, N> where
    D: 'static,
    P: Ord,
    T: Timer,
    N: ArrayLength<TopqItem<D, P, T>>, 
[src]

type Item = &'a TopqItem<D, P, T>

The type of the elements being iterated over.

type IntoIter = Iter<'a, TopqItem<D, P, T>>

Which kind of iterator are we turning this into?

impl<'a, D, P, T, N> IntoIterator for &'a mut Topq<D, P, T, N> where
    D: 'static,
    P: Ord,
    T: Timer,
    N: ArrayLength<TopqItem<D, P, T>>, 
[src]

type Item = &'a mut TopqItem<D, P, T>

The type of the elements being iterated over.

type IntoIter = IterMut<'a, TopqItem<D, P, T>>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<D, P, T, N> Send for Topq<D, P, T, N> where
    D: Send,
    P: Send,
    T: Send,
    <T as Timer>::Time: Send

impl<D, P, T, N> Sync for Topq<D, P, T, N> where
    D: Sync,
    P: Sync,
    T: Sync,
    <T as Timer>::Time: Sync

impl<D, P, T, N> Unpin for Topq<D, P, T, N> where
    T: Unpin,
    <N as ArrayLength<TopqItem<D, P, T>>>::ArrayType: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.