Skip to main content

PrioritySource

Struct PrioritySource 

Source
pub struct PrioritySource<I> {
    pub priority: i32,
    pub stream: I,
}
Expand description

A source + the priority it carries. Higher priority wins on key ties. Equal-priority ties fall through to registration order (the index in the new(...) argument list).

Fields§

§priority: i32§stream: I

Implementations§

Source§

impl<I> PrioritySource<I>

Source

pub fn new(priority: i32, stream: I) -> Self

Examples found in repository?
examples/perf_features.rs (line 486)
475fn priority_sources(n: usize) -> Vec<PrioritySource<std::vec::IntoIter<PriorityEntry<u64, u64>>>> {
476    let per = n / STREAMS;
477    (0..STREAMS)
478        .map(|s| {
479            let stream = (0..per)
480                .map(move |i| {
481                    let key = ((s + i * STREAMS) as u64) / 2;
482                    PriorityEntry::new(key, key)
483                })
484                .collect::<Vec<_>>()
485                .into_iter();
486            PrioritySource::new((STREAMS - s) as i32, stream)
487        })
488        .collect()
489}
More examples
Hide additional examples
examples/sample_app.rs (lines 212-219)
209fn memtable_wins_the_read() {
210    use subms_merge_iterator::{PriorityEntry, PriorityMergeIterator, PrioritySource};
211    println!("\n== priority: the memtable is authoritative ==");
212    let memtable = PrioritySource::new(
213        100,
214        PRICE_MEMTABLE
215            .iter()
216            .map(|&(k, v)| PriorityEntry::new(k, v))
217            .collect::<Vec<_>>()
218            .into_iter(),
219    );
220    let flushed = PrioritySource::new(
221        10,
222        PRICE_FLUSHED
223            .iter()
224            .map(|&(k, v)| PriorityEntry::new(k, v))
225            .collect::<Vec<_>>()
226            .into_iter(),
227    );
228
229    let view: Vec<(&str, i64)> = PriorityMergeIterator::new([memtable, flushed])
230        .map(|e| (e.key, e.value))
231        .collect();
232    println!("  resolved read view: {view:?}");
233    assert_eq!(
234        view,
235        vec![("AAPL", 152), ("MSFT", 300)],
236        "the memtable wins AAPL despite being registered first"
237    );
238}

Auto Trait Implementations§

§

impl<I> Freeze for PrioritySource<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for PrioritySource<I>
where I: RefUnwindSafe,

§

impl<I> Send for PrioritySource<I>
where I: Send,

§

impl<I> Sync for PrioritySource<I>
where I: Sync,

§

impl<I> Unpin for PrioritySource<I>
where I: Unpin,

§

impl<I> UnsafeUnpin for PrioritySource<I>
where I: UnsafeUnpin,

§

impl<I> UnwindSafe for PrioritySource<I>
where I: 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.