EventQueue

Struct EventQueue 

Source
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>

Source

pub fn new(capacity: usize) -> Self

Return an event queue of the given max capacity.

Source

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)).

Source

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.

Source

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.

Source

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.

Source

pub fn get(&self, id: &EventId<I>) -> Option<&T>

Lookup event status given an event id. This operation is O(log(n)).

Source

pub fn remove(&mut self, id: &EventId<I>) -> Option<T>

Lookup event status given an event id. This operation is O(log(n)).

Source

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)).

Source

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)).

Source

pub fn capacity(&self) -> usize

Return max capacity.

Source

pub fn len(&self) -> usize

Return number of events in the queue. This operation is constant time.

Source

pub fn is_full(&self) -> bool

Return true if the queue is at its max capacity. This operation is constant time.

Source

pub fn is_empty(&self) -> bool

Return true if the queue is empty. This operation is constant time.

Source

pub fn iter(&self) -> Box<dyn Iterator<Item = (&EventId<I>, &T)> + '_>

Return an iterator of all events in the order of their EventId, i.e., ordered by expiry first, then by nonce.

Trait Implementations§

Source§

impl<I: Ord + CandidType, T: CandidType> CandidType for EventQueue<I, T>

Source§

fn _ty() -> Type

Source§

fn id() -> TypeId

Source§

fn idl_serialize<__S>(&self, __serializer: __S) -> Result<(), __S::Error>
where __S: Serializer,

Source§

fn ty() -> Type

Source§

impl<I: Clone + Ord, T: Clone> Clone for EventQueue<I, T>

Source§

fn clone(&self) -> EventQueue<I, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug + Ord, T: Debug> Debug for EventQueue<I, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: Ord, T> Default for EventQueue<I, T>

Source§

fn default() -> Self

Return an empty event queue of zero capacity.

Source§

impl<'de, I, T> Deserialize<'de> for EventQueue<I, T>
where I: Deserialize<'de> + Ord, T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<I: Hash + Ord, T: Hash> Hash for EventQueue<I, T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I, T> Serialize for EventQueue<I, T>
where I: Serialize + Ord, T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<I, T> Freeze for EventQueue<I, T>

§

impl<I, T> RefUnwindSafe for EventQueue<I, T>

§

impl<I, T> Send for EventQueue<I, T>
where T: Send, I: Send,

§

impl<I, T> Sync for EventQueue<I, T>
where T: Sync, I: Sync,

§

impl<I, T> Unpin for EventQueue<I, T>

§

impl<I, T> UnwindSafe for EventQueue<I, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,