pub struct TournamentTree<I, T>{ /* private fields */ }Expand description
Tournament Tree for K-way merge of sorted iterators
§Usage Example
ⓘ
let iters = vec![
vec![1, 4, 7].into_iter().peekable(),
vec![2, 5, 8].into_iter().peekable(),
vec![3, 6, 9].into_iter().peekable(),
];
let mut tree = TournamentTree::new(iters);
while let Some((source_idx, value)) = tree.pop() {
println!("Source {}: {}", source_idx, value);
}
// Outputs: 1, 2, 3, 4, 5, 6, 7, 8, 9 (in order)Implementations§
Source§impl<I, T> TournamentTree<I, T>
impl<I, T> TournamentTree<I, T>
Sourcepub fn new(iters: Vec<I>) -> Self
pub fn new(iters: Vec<I>) -> Self
Create a new tournament tree from K iterators
Time complexity: O(K)
Sourcepub fn pop(&mut self) -> Option<(usize, T)>
pub fn pop(&mut self) -> Option<(usize, T)>
Get the next minimum element
Returns (source_index, element) or None if all sources exhausted. Time complexity: O(log K)
Sourcepub fn peek(&mut self) -> Option<(usize, &T)>
pub fn peek(&mut self) -> Option<(usize, &T)>
Peek at the next minimum element without consuming it
Sourcepub fn source_count(&self) -> usize
pub fn source_count(&self) -> usize
Get the number of sources
Auto Trait Implementations§
impl<I, T> Freeze for TournamentTree<I, T>
impl<I, T> RefUnwindSafe for TournamentTree<I, T>where
T: RefUnwindSafe,
I: RefUnwindSafe,
impl<I, T> Send for TournamentTree<I, T>
impl<I, T> Sync for TournamentTree<I, T>
impl<I, T> Unpin for TournamentTree<I, T>
impl<I, T> UnsafeUnpin for TournamentTree<I, T>
impl<I, T> UnwindSafe for TournamentTree<I, T>where
T: UnwindSafe,
I: UnwindSafe,
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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