Skip to main content

KeyedInFlightLedger

Struct KeyedInFlightLedger 

Source
pub struct KeyedInFlightLedger<K, C> { /* private fields */ }
Expand description

Holds at most one in-flight item per key, drives their lifecycle uniformly, and records recognitions for latent queries. The keyed analogue of InFlightLedger, for calculators that track a candidate per subject (e.g. per player).

Implementations§

Source§

impl<K, C> KeyedInFlightLedger<K, C>

Source

pub fn new() -> Self

Source

pub fn with_history_window(history_window: f32) -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source§

impl<K: Eq + Hash + Clone, C> KeyedInFlightLedger<K, C>

Source

pub fn arm(&mut self, key: K, item: C)

Arm (or replace) the in-flight item for key.

Source

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

Source

pub fn get(&self, key: &K) -> Option<&C>

Source

pub fn get_mut(&mut self, key: &K) -> Option<&mut C>

Source

pub fn entry_or_insert_with( &mut self, key: K, default: impl FnOnce() -> C, ) -> &mut C

Access the in-flight item for key, inserting one produced by default if absent. Mirrors HashMap::entry(..).or_insert_with(..).

Source

pub fn keys(&self) -> impl Iterator<Item = &K> + '_

Source

pub fn values(&self) -> impl Iterator<Item = &C> + '_

Source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut C> + '_

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, &C)> + '_

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut C)> + '_

Source

pub fn retain(&mut self, keep: impl FnMut(&K, &C) -> bool)

Keep only the items for which keep returns true, discarding the rest without finalizing them (e.g. pruning stale candidates).

Source

pub fn discard(&mut self, key: &K) -> Option<C>

Remove the item for key without recording it as having happened (it is abandoned, not finalized).

Source

pub fn clear(&mut self)

Discard every in-flight item without finalizing any (e.g. abandoning all candidates when their precondition no longer holds).

Source§

impl<K: Eq + Hash + Clone, C: InFlightItem> KeyedInFlightLedger<K, C>

Source

pub fn finalize(&mut self, key: &K, _reason: FinalizeReason) -> Option<C>

Finalize the item for key, logging it for latent queries and returning it for the caller to convert into an event.

Source

pub fn advance( &mut self, now: f32, step: impl FnMut(&K, &mut C) -> Disposition, ) -> Vec<(K, C, FinalizeReason)>

Advance every in-flight item with step, which receives the key and a mutable item and returns a Disposition. now bounds the latent-query history. Finalized items are returned with their key and reason.

Source

pub fn apply_boundary( &mut self, boundary: Boundary, ) -> Vec<(K, C, FinalizeReason)>

Apply boundary to every in-flight item via InFlightItem::on_boundary.

Source

pub fn finish(&mut self) -> Vec<(K, C, FinalizeReason)>

Finalize everything still in flight at end of stream.

Source

pub fn happened_within( &self, now: f32, window: f32, committed_only: bool, ) -> bool

Source

pub fn recognitions_within( &self, now: f32, window: f32, committed_only: bool, ) -> impl Iterator<Item = Recognition> + '_

All recognitions within window seconds before now, across in-flight and finalized items.

Trait Implementations§

Source§

impl<K: Clone, C: Clone> Clone for KeyedInFlightLedger<K, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, C: Debug> Debug for KeyedInFlightLedger<K, C>

Source§

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

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

impl<K, C> Default for KeyedInFlightLedger<K, C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: Eq + Hash, C: PartialEq> PartialEq for KeyedInFlightLedger<K, C>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<K, C> Freeze for KeyedInFlightLedger<K, C>
where HashMap<K, C>: Freeze,

§

impl<K, C> RefUnwindSafe for KeyedInFlightLedger<K, C>
where HashMap<K, C>: RefUnwindSafe,

§

impl<K, C> Send for KeyedInFlightLedger<K, C>
where HashMap<K, C>: Send,

§

impl<K, C> Sync for KeyedInFlightLedger<K, C>
where HashMap<K, C>: Sync,

§

impl<K, C> Unpin for KeyedInFlightLedger<K, C>
where HashMap<K, C>: Unpin,

§

impl<K, C> UnsafeUnpin for KeyedInFlightLedger<K, C>
where HashMap<K, C>: UnsafeUnpin,

§

impl<K, C> UnwindSafe for KeyedInFlightLedger<K, C>
where HashMap<K, C>: 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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.