pub struct EventQueue<I: Ord, T> { /* private fields */ }Expand description
An event queue is an ordered list of events of nonce type I and status type T.
Its max capacity is fixed at initialization.
Implementations§
Source§impl<I: Ord, T> EventQueue<I, T>
impl<I: Ord, T> EventQueue<I, T>
Sourcepub fn insert(
&mut self,
id: EventId<I>,
event: T,
) -> Result<(), EventQueueFullError>where
I: Clone,
pub fn insert(
&mut self,
id: EventId<I>,
event: T,
) -> Result<(), EventQueueFullError>where
I: Clone,
Insert an event of the given id and status into the queue.
Return error if the queue is full.
This operation is O(log(n)).
Sourcepub fn pop_front<F: Fn(&T) -> bool>(
&mut self,
matching: F,
) -> Option<(EventId<I>, T)>where
I: Clone,
pub fn pop_front<F: Fn(&T) -> bool>(
&mut self,
matching: F,
) -> Option<(EventId<I>, T)>where
I: Clone,
Remove and return the first matching event. This operation is linear in the events it has to search through.
Sourcepub fn purge<F: Fn(&T) -> bool>(&mut self, expiry: u64, matching: F)where
I: Default,
pub fn purge<F: Fn(&T) -> bool>(&mut self, expiry: u64, matching: F)where
I: Default,
Remove all events of the matching status with an expiry less than the given expiry. This operation is in the number of events matching the expiry condition.
Sourcepub fn purge_expired(&mut self, expiry: u64)where
I: Default,
pub fn purge_expired(&mut self, expiry: u64)where
I: Default,
Remove all events with an expiry less than the given expiry.
This operation is O(log(n))+O(m), where m is the number of events removed.
Sourcepub fn get(&self, id: &EventId<I>) -> Option<&T>
pub fn get(&self, id: &EventId<I>) -> Option<&T>
Lookup event status given an event id.
This operation is O(log(n)).
Sourcepub fn remove(&mut self, id: &EventId<I>) -> Option<T>
pub fn remove(&mut self, id: &EventId<I>) -> Option<T>
Lookup event status given an event id.
This operation is O(log(n)).
Sourcepub fn modify<F: FnOnce(&mut T)>(&mut self, id: EventId<I>, f: F)
pub fn modify<F: FnOnce(&mut T)>(&mut self, id: EventId<I>, f: F)
Modify the status of an event given its id.
This operation is O(log(n)).
Sourcepub fn find(&self, nonce: &I) -> Option<(&EventId<I>, &T)>
pub fn find(&self, nonce: &I) -> Option<(&EventId<I>, &T)>
Return both an event id and its status if the given nonce is found.
This operation is O(log(n)).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return number of events in the queue. This operation is constant time.
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Return true if the queue is at its max capacity. This operation is constant time.
Trait Implementations§
Source§impl<I: Ord + CandidType, T: CandidType> CandidType for EventQueue<I, T>
impl<I: Ord + CandidType, T: CandidType> CandidType for EventQueue<I, T>
Source§impl<I: Clone + Ord, T: Clone> Clone for EventQueue<I, T>
impl<I: Clone + Ord, T: Clone> Clone for EventQueue<I, T>
Source§fn clone(&self) -> EventQueue<I, T>
fn clone(&self) -> EventQueue<I, T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more