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: IImplementations§
Source§impl<I> PrioritySource<I>
impl<I> PrioritySource<I>
Sourcepub fn new(priority: i32, stream: I) -> Self
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
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> 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