Skip to content

Instantly share code, notes, and snippets.

View dat2's full-sized avatar

Nicholas Dujay dat2

View GitHub Profile
@dat2
dat2 / ordered_iterator.rs
Created March 30, 2017 14:05
Rust implementation of sorted iterator based on 2 input iterators
use std::iter::{Iterator, Peekable};
// this struct lets you create an iterator from 2 sub iterators, and it will
// automatically return the interleaved, sorted results without much cost
struct OrderedIterator<I: Ord + Clone, P: Iterator<Item = I>> {
first: Peekable<P>,
second: Peekable<P>,
pop_from: usize,
first_empty: bool,
second_empty: bool,