fn map_blocks_to_columns(
    blocks: &mut [Option<ValuePair>],
    dst: &mut BTreeMap<String, ColumnData>,
) -> Option<i64> {
    // First determine the minimum timestamp in any of the input blocks or return
    // None if all of the blocks have been drained.
    let min_ts = blocks.iter().flatten().map(ValuePair::timestamp).min()?;

    for (i, column) in dst.values_mut().enumerate() {
        match &mut blocks[i] {
            Some(pair) => {
                // If this candidate has the `min_ts` time-stamp then emit its
                // value to the output column, otherwise emit a None value.
                match pair {
                    ValuePair::F64((ts, value)) => {
                        if let ColumnData::Float(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::I64((ts, value)) => {
                        if let ColumnData::Integer(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::Bool((ts, value)) => {
                        if let ColumnData::Bool(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::Str((ts, value)) => {
                        if let ColumnData::Str(vs) = column {
                            // TODO(edd): perf - Remove this cloning....
                            if *ts == min_ts {
                                vs.push(Some(value.clone()));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::U64((ts, value)) => {
                        if let ColumnData::Unsigned(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                }
            }
            // This field value pair doesn't have a value for the min time-stamp
            None => match column {
                ColumnData::Float(vs) => {
                    vs.push(None);
                }
                ColumnData::Integer(vs) => {
                    vs.push(None);
                }
                ColumnData::Bool(vs) => {
                    vs.push(None);
                }
                ColumnData::Str(vs) => {
                    vs.push(None);
                }
                ColumnData::Unsigned(vs) => {
                    vs.push(None);
                }
            },
        }
    }
    Some(min_ts)
}
// Given a set of input blocks, where each block comprises two equally sized
// arrays of timestamps and values, join the head of each input block's value
// array by the head of the corresponding timestamp column.
//
Given a set of input blocks, where each block comprises two equally sized
arrays of timestamps and values, join the head of each input block's value
array by the head of the corresponding timestamp column.
Given a set of input blocks where each block comprises two equally sized arrays of timestamps and values join the head of each input block ' s value array by the head of the corresponding timestamp column .
fn map_blocks_to_columns(
    blocks: &mut [Option<ValuePair>],
    dst: &mut BTreeMap<String, ColumnData>,
) -> Option<i64> {
    // First determine the minimum timestamp in any of the input blocks or return
    // None if all of the blocks have been drained.
    let min_ts = blocks.iter().flatten().map(ValuePair::timestamp).min()?;
    for (i, column) in dst.values_mut().enumerate() {
        match &mut blocks[i] {
            Some(pair) => {
                // If this candidate has the `min_ts` time-stamp then emit its
                // value to the output column, otherwise emit a None value.
                match pair {
                    ValuePair::F64((ts, value)) => {
                        if let ColumnData::Float(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::I64((ts, value)) => {
                        if let ColumnData::Integer(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::Bool((ts, value)) => {
                        if let ColumnData::Bool(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::Str((ts, value)) => {
                        if let ColumnData::Str(vs) = column {
                            // TODO(edd): perf - Remove this cloning....
                            if *ts == min_ts {
                                vs.push(Some(value.clone()));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                    ValuePair::U64((ts, value)) => {
                        if let ColumnData::Unsigned(vs) = column {
                            if *ts == min_ts {
                                vs.push(Some(*value));
                                blocks[i] = None;
                            } else {
                                vs.push(None); // block has a value available
                                               // but timestamp doesn't join
                            }
                        };
                    }
                }
            }
            // This field value pair doesn't have a value for the min time-stamp
            None => match column {
                ColumnData::Float(vs) => {
                    vs.push(None);
                }
                ColumnData::Integer(vs) => {
                    vs.push(None);
                }
                ColumnData::Bool(vs) => {
                    vs.push(None);
                }
                ColumnData::Str(vs) => {
                    vs.push(None);
                }
                ColumnData::Unsigned(vs) => {
                    vs.push(None);
                }
            },
        }
    }
    Some(min_ts)
}
fn map_blocks_to_columns ( blocks : & mut [ Option < ValuePair > ] , dst : & mut BTreeMap < String , ColumnData > , ) -> Option < i64 > { // First determine the minimum timestamp in any of the input blocks or return // None if all of the blocks have been drained. let min_ts = blocks . iter ( ) . flatten ( ) . map ( ValuePair :: timestamp ) . min ( ) ? ; for ( i , column ) in dst . values_mut ( ) . enumerate ( ) { match & mut blocks [ i ] { Some ( pair ) => { // If this candidate has the `min_ts` time-stamp then emit its // value to the output column, otherwise emit a None value. match pair { ValuePair :: F64 ( ( ts , value ) ) => { if let ColumnData :: Float ( vs ) = column { if * ts == min_ts { vs . push ( Some ( * value ) ) ; blocks [ i ] = None ; } else { vs . push ( None ) ; // block has a value available // but timestamp doesn't join } } ; } ValuePair :: I64 ( ( ts , value ) ) => { if let ColumnData :: Integer ( vs ) = column { if * ts == min_ts { vs . push ( Some ( * value ) ) ; blocks [ i ] = None ; } else { vs . push ( None ) ; // block has a value available // but timestamp doesn't join } } ; } ValuePair :: Bool ( ( ts , value ) ) => { if let ColumnData :: Bool ( vs ) = column { if * ts == min_ts { vs . push ( Some ( * value ) ) ; blocks [ i ] = None ; } else { vs . push ( None ) ; // block has a value available // but timestamp doesn't join } } ; } ValuePair :: Str ( ( ts , value ) ) => { if let ColumnData :: Str ( vs ) = column { // TODO(edd): perf - Remove this cloning.... if * ts == min_ts { vs . push ( Some ( value . clone ( ) ) ) ; blocks [ i ] = None ; } else { vs . push ( None ) ; // block has a value available // but timestamp doesn't join } } ; } ValuePair :: U64 ( ( ts , value ) ) => { if let ColumnData :: Unsigned ( vs ) = column { if * ts == min_ts { vs . push ( Some ( * value ) ) ; blocks [ i ] = None ; } else { vs . push ( None ) ; // block has a value available // but timestamp doesn't join } } ; } } } // This field value pair doesn't have a value for the min time-stamp None => match column { ColumnData :: Float ( vs ) => { vs . push ( None ) ; } ColumnData :: Integer ( vs ) => { vs . push ( None ) ; } ColumnData :: Bool ( vs ) => { vs . push ( None ) ; } ColumnData :: Str ( vs ) => { vs . push ( None ) ; } ColumnData :: Unsigned ( vs ) => { vs . push ( None ) ; } } , } } Some ( min_ts ) }
Given a set of input blocks, where each block comprises two equally sized
arrays of timestamps and values, join the head of each input block's value
array by the head of the corresponding timestamp column.
Given a set of input blocks where each block comprises two equally sized arrays of timestamps and values join the head of each input block ' s value array by the head of the corresponding timestamp column .
blocks
&mut [Option<ValuePair>]
dst
&mut BTreeMap<String, ColumnData>
blocks
&mut [Option<ValuePair>]
dst
&mut BTreeMap<String, ColumnData>