Skip to main content

GenerationalBuffer

Struct GenerationalBuffer 

Source
struct GenerationalBuffer<S> {
    shares: VecDeque<(HoprSurbId, S)>,
    plain: VecDeque<(HoprSurbId, S)>,
    generation: Option<u8>,
}
Expand description

The mutex-protected state of a SurbRingBuffer: the SURBs, in their two tiers, and the highest generation seen.

All of it lives under one lock so that clearing both tiers and advancing the generation on a newer batch is atomic against a concurrent pop, and so that the combined length the capacity bounds is never seen or changed half-way.

Fields§

§shares: VecDeque<(HoprSurbId, S)>

SURBs carrying a PIX share, in insertion order. The Entry emits shares in SSA-index order, so FIFO here is also lowest-SSA-first.

§plain: VecDeque<(HoprSurbId, S)>

SURBs carrying no share: pure return paths.

§generation: Option<u8>

Highest generation seen; None until the first push.

Implementations§

Source§

impl<S> GenerationalBuffer<S>

Source

fn len(&self) -> usize

SURBs held across both tiers: the quantity the capacity bounds.

Source

fn clear(&mut self)

Drops every SURB of both tiers.

Source

fn next_tier(&self) -> &VecDeque<(HoprSurbId, S)>

The tier a pop takes from: share-bearing SURBs for as long as there are any, share-less ones only once there are none. The single place that priority is decided, so peeking and popping — and with them the exact-ID pop — cannot disagree about which SURB is next.

Source

fn next_tier_mut(&mut self) -> &mut VecDeque<(HoprSurbId, S)>

As next_tier, for removing from it.

Source

fn peek_next(&self) -> Option<&(HoprSurbId, S)>

The SURB the next pop would take: the oldest of the next tier. Peeking and popping both go through next_tier, so they stay in step.

Source

fn pop_next(&mut self) -> Option<(HoprSurbId, S)>

Removes and returns the oldest SURB of the next tier.

Source

fn make_room_for(&mut self, newcomer_carries_share: bool) -> MadeRoom

Makes room in a full buffer for one more SURB by evicting the oldest share-less one.

Failing that, the oldest share-bearing one goes if the newcomer carries a share too. A share-less newcomer is turned away instead — a return path is not worth a share nothing can replace — and MadeRoom::Refused says so: there is no room for it, and the caller must not insert it.

What happened is returned rather than just whether there is room, because the cost differs: a share-less SURB is only a lost return path, a share-bearing one is a share nothing can replace.

Trait Implementations§

Source§

impl<S: Debug> Debug for GenerationalBuffer<S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for GenerationalBuffer<S>

§

impl<S> RefUnwindSafe for GenerationalBuffer<S>
where S: RefUnwindSafe,

§

impl<S> Send for GenerationalBuffer<S>
where S: Send,

§

impl<S> Sync for GenerationalBuffer<S>
where S: Sync,

§

impl<S> Unpin for GenerationalBuffer<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for GenerationalBuffer<S>

§

impl<S> UnwindSafe for GenerationalBuffer<S>
where S: 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more