// Merges items from an array of layers using the provided merge function. The merge function
// is repeatedly provided the lowest and the second lowest element, if one exists. In cases
// where the two lowest elements compare equal, the element with the lowest layer
// (i.e. whichever comes first in the layers array) will come first.
Merges items from an array of layers using the provided merge function. The merge function
is repeatedly provided the lowest and the second lowest element, if one exists. In cases
where the two lowest elements compare equal, the element with the lowest layer
will come first.
Merges items from an array of layers using the provided merge function . The merge function is repeatedly provided the lowest and the second lowest element if one exists . In cases where the two lowest elements compare equal the element with the lowest layer will come first .
async fn advance_impl(&mut self) -> Result<(), Error> {
        // Push the iterator for the current item (if we have one) onto the heap.
        if let Some(iterator) = self.item.take_iterator() {
            iterator.advance().await?;
            if iterator.is_some() {
                self.heap.push(iterator);
            }
        }
        while !self.heap.is_empty() {
            let lowest = self.heap.pop().unwrap();
            let maybe_second_lowest = self.heap.pop();
            if let Some(second_lowest) = maybe_second_lowest {
                let result = (self.merge_fn)(&lowest, &second_lowest);
                match result {
                    MergeResult::EmitLeft => {
                        self.heap.push(second_lowest);
                        self.item = CurrentItem::Iterator(lowest);
                        return Ok(());
                    }
                    MergeResult::Other { emit, left, right } => {
                        try_join!(
                            lowest.maybe_discard(&left),
                            second_lowest.maybe_discard(&right)
                        )?;
                        self.update_item(lowest, left);
                        self.update_item(second_lowest, right);
                        if let Some(emit) = emit {
                            self.item = CurrentItem::Item(emit);
                            return Ok(());
                        }
                    }
                }
            } else {
                self.item = CurrentItem::Iterator(lowest);
                return Ok(());
            }
        }
        self.item = CurrentItem::None;
        Ok(())
    }
async fn advance_impl ( & mut self ) -> Result < ( ) , Error > { // Push the iterator for the current item (if we have one) onto the heap. if let Some ( iterator ) = self . item . take_iterator ( ) { iterator . advance ( ) . await ? ; if iterator . is_some ( ) { self . heap . push ( iterator ) ; } } while ! self . heap . is_empty ( ) { let lowest = self . heap . pop ( ) . unwrap ( ) ; let maybe_second_lowest = self . heap . pop ( ) ; if let Some ( second_lowest ) = maybe_second_lowest { let result = ( self . merge_fn ) ( & lowest , & second_lowest ) ; match result { MergeResult :: EmitLeft => { self . heap . push ( second_lowest ) ; self . item = CurrentItem :: Iterator ( lowest ) ; return Ok ( ( ) ) ; } MergeResult :: Other { emit , left , right } => { try_join ! ( lowest maybe_discard ( left ) second_lowest maybe_discard ( right ) ) ? ; self . update_item ( lowest , left ) ; self . update_item ( second_lowest , right ) ; if let Some ( emit ) = emit { self . item = CurrentItem :: Item ( emit ) ; return Ok ( ( ) ) ; } } } } else { self . item = CurrentItem :: Iterator ( lowest ) ; return Ok ( ( ) ) ; } } self . item = CurrentItem :: None ; Ok ( ( ) ) }
Merges items from an array of layers using the provided merge function.
Merges items from an array of layers using the provided merge function .
&mut self