pub struct ValueCachedQueue<Q> {
queue: Q,
value_cache: HashMap<u32, HoprBalance>,
}Expand description
Adapter for TicketQueue that caches the total ticket value per channel epoch.
The cache value is updated with each push and pop operation.
The total_value method
returns the cached value if available, otherwise it delegates to the underlying queue.
If min_index is provided, the cache is bypassed and the underlying queue is queried directly.
All other calls are simply delegated to the underlying queue.
The implementation uses hashbrown::HashMap for efficient key-value storage.
Fields§
§queue: Q§value_cache: HashMap<u32, HoprBalance>Implementations§
Source§impl<Q: TicketQueue> ValueCachedQueue<Q>
impl<Q: TicketQueue> ValueCachedQueue<Q>
Trait Implementations§
Source§impl<Q: Clone> Clone for ValueCachedQueue<Q>
impl<Q: Clone> Clone for ValueCachedQueue<Q>
Source§fn clone(&self) -> ValueCachedQueue<Q>
fn clone(&self) -> ValueCachedQueue<Q>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Q: Debug> Debug for ValueCachedQueue<Q>
impl<Q: Debug> Debug for ValueCachedQueue<Q>
Source§impl<Q: TicketQueue> TicketQueue for ValueCachedQueue<Q>
impl<Q: TicketQueue> TicketQueue for ValueCachedQueue<Q>
type Error = <Q as TicketQueue>::Error
Source§fn push(&mut self, ticket: RedeemableTicket) -> Result<(), Self::Error>
fn push(&mut self, ticket: RedeemableTicket) -> Result<(), Self::Error>
Add a ticket to the queue.
Source§fn pop(&mut self) -> Result<Option<RedeemableTicket>, Self::Error>
fn pop(&mut self) -> Result<Option<RedeemableTicket>, Self::Error>
Remove and return the next ticket in-order from the queue. Read more
Source§fn peek(&self) -> Result<Option<RedeemableTicket>, Self::Error>
fn peek(&self) -> Result<Option<RedeemableTicket>, Self::Error>
Return the next ticket in-order from the queue without removing it. Read more
Source§fn iter_unordered(
&self,
) -> Result<impl Iterator<Item = Result<RedeemableTicket, Self::Error>>, Self::Error>
fn iter_unordered( &self, ) -> Result<impl Iterator<Item = Result<RedeemableTicket, Self::Error>>, Self::Error>
Iterate over all tickets in the queue in arbitrary order. Read more
Auto Trait Implementations§
impl<Q> Freeze for ValueCachedQueue<Q>where
Q: Freeze,
impl<Q> RefUnwindSafe for ValueCachedQueue<Q>where
Q: RefUnwindSafe,
impl<Q> Send for ValueCachedQueue<Q>where
Q: Send,
impl<Q> Sync for ValueCachedQueue<Q>where
Q: Sync,
impl<Q> Unpin for ValueCachedQueue<Q>where
Q: Unpin,
impl<Q> UnwindSafe for ValueCachedQueue<Q>where
Q: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more