Skip to main content

KeyedHashedWheelTimer

Struct KeyedHashedWheelTimer 

Source
pub struct KeyedHashedWheelTimer<T, K, F>
where K: Eq + Hash + Clone, F: Fn(&T) -> K,
{ /* private fields */ }
Expand description

Keyed wrapper over HashedWheelTimer.

A dedup key is produced by dedup_key_fn. Scheduling/updating an event with an existing key replaces the previous one.

Implementations§

Source§

impl<T, K, F> KeyedHashedWheelTimer<T, K, F>
where K: Eq + Hash + Clone, F: Fn(&T) -> K,

Source

pub fn new(buckets_num: usize, dedup_key_fn: F) -> Self

Creates a keyed timer.

Source

pub fn count_all(&self) -> usize

Returns total number of scheduled events.

Source

pub fn count_in_bucket( &self, bucket_index: usize, ) -> Result<usize, TimeWheelError>

Returns number of events in bucket by index.

Source

pub fn is_empty(&self) -> bool

Returns true when no events are scheduled.

Source

pub fn is_empty_bucket( &self, bucket_index: usize, ) -> Result<bool, TimeWheelError>

Returns true when bucket contains no events.

Source

pub fn has_events_in_current_tick(&self) -> bool

Returns true if current tick still has events to pop.

Source

pub fn curr_tick(&self) -> u64

Returns current absolute tick.

Source

pub fn curr_bucket(&self) -> usize

Returns current bucket index.

Source

pub fn curr_delta_tick(&self) -> u64

Returns current wave (delta_tick) in the current tick.

Source

pub fn curr_seq_id(&self) -> EventId

Returns latest assigned sequence ID.

Source

pub fn step(&mut self)

Advances timer by one tick.

Source

pub fn reset(&mut self)

Clears all events and key index, then resets timer state.

Source

pub fn contains_by_id(&self, id: EventId) -> bool

Returns true if event with ID exists.

Source

pub fn contains_by_key(&self, key: &K) -> bool

Returns true if key exists.

Source

pub fn id_by_key(&self, key: &K) -> Option<EventId>

Returns event ID by key.

Source

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

Returns event by ID.

Source

pub fn get_by_key(&self, key: &K) -> Option<&Event<T>>

Returns event by key.

Source

pub fn schedule(&mut self, on_tick: u64, data: T) -> KeyedScheduleResult

Schedules an event.

If key already exists, previous event is replaced.

Source

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

Removes event by ID and updates key index.

Source

pub fn remove_by_key(&mut self, key: &K) -> Option<Event<T>>

Removes event by dedup key.

Source

pub fn update( &mut self, id: EventId, on_tick: u64, data: T, ) -> Option<KeyedUpdateResult>

Updates event by ID and applies key replacement semantics.

Source

pub fn update_by_key( &mut self, key: &K, on_tick: u64, data: T, ) -> Option<KeyedUpdateResult>

Updates event by key.

Source

pub fn reschedule( &mut self, id: EventId, on_tick: u64, ) -> Option<KeyedUpdateResult>

Reschedules event by ID preserving payload and key.

Source

pub fn reschedule_by_key( &mut self, key: &K, on_tick: u64, ) -> Option<KeyedUpdateResult>

Reschedules event by key.

Source

pub fn pop_events(&mut self) -> Vec<Event<T>>

Pops one current-tick wave and keeps key index in sync.

Trait Implementations§

Source§

impl<T: Debug, K, F> Debug for KeyedHashedWheelTimer<T, K, F>
where K: Eq + Hash + Clone + Debug, F: Fn(&T) -> K + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, K, F> Freeze for KeyedHashedWheelTimer<T, K, F>
where F: Freeze,

§

impl<T, K, F> RefUnwindSafe for KeyedHashedWheelTimer<T, K, F>

§

impl<T, K, F> Send for KeyedHashedWheelTimer<T, K, F>
where F: Send, K: Send, T: Send,

§

impl<T, K, F> Sync for KeyedHashedWheelTimer<T, K, F>
where F: Sync, K: Sync, T: Sync,

§

impl<T, K, F> Unpin for KeyedHashedWheelTimer<T, K, F>
where F: Unpin, K: Unpin, T: Unpin,

§

impl<T, K, F> UnwindSafe for KeyedHashedWheelTimer<T, K, F>
where F: UnwindSafe, K: UnwindSafe, T: UnwindSafe,

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