pub struct Deadlines<K> { /* private fields */ }Expand description
A deadline heap keyed by K, holding at most one deadline per key.
next_timeout is O(1) and
set/pop_expired are O(log n), so a host
with many connections or requests never rescans them to arm its timer.
Replaced deadlines stay in the heap until they surface and are discarded;
the heap is rebuilt whenever they outnumber the live ones, so its size stays
within a constant factor of len.
Implementations§
Source§impl<K: Copy + Eq + Hash> Deadlines<K>
impl<K: Copy + Eq + Hash> Deadlines<K>
pub fn new() -> Self
Sourcepub fn set(&mut self, key: K, deadline: Option<Instant>)
pub fn set(&mut self, key: K, deadline: Option<Instant>)
Replace key’s deadline; None removes it.
pub fn get(&self, key: K) -> Option<Instant>
Sourcepub fn next_timeout(&self) -> Option<Instant>
pub fn next_timeout(&self) -> Option<Instant>
The earliest live deadline.
Sourcepub fn pop_expired(&mut self, now: Instant) -> Option<K>
pub fn pop_expired(&mut self, now: Instant) -> Option<K>
Remove and return one key whose deadline is at or before now, earliest
first. Call repeatedly until None.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<K> Forget for Deadlines<K>
impl<K> Freeze for Deadlines<K>
impl<K> RefUnwindSafe for Deadlines<K>
impl<K> Send for Deadlines<K>
impl<K> Sync for Deadlines<K>
impl<K> Unpin for Deadlines<K>
impl<K> UnsafeUnpin for Deadlines<K>
impl<K> UnwindSafe for Deadlines<K>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more