fn from_slice_with_byte_trimming(arr: &[f64], range: (f64, f64)) -> FloatEncoding {
    // determine min and max values.
    let min = range.0;
    let max = range.1;

    // If true then use RLE after byte trimming.
    let rle = should_rle_from_iter(arr.len(), arr.iter().map(Some));

    // This match is carefully ordered. It prioritises smaller physical
    // datatypes that can correctly represent the provided logical data.
    let transcoder = FloatByteTrimmer {};
    let transcoder_name = format!("{}", &transcoder);
    let (enc, name) = match (min, max) {
        // encode as u8 values
        (min, max) if min >= 0.0 && max <= u8::MAX as f64 => {
            let arr = arr
                .iter()
                .map::<u8, _>(|v| transcoder.encode(*v))
                .collect::<Vec<_>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_U8-{}", transcoder_name, name))
        }
        // encode as i8 values
        (min, max) if min >= i8::MIN as f64 && max <= i8::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<i8>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_I8-{}", transcoder_name, name))
        }
        // encode as u16 values
        (min, max) if min >= 0.0 && max <= u16::MAX as f64 => {
            let arr = arr
                .iter()
                .map::<u16, _>(|v| transcoder.encode(*v))
                .collect::<Vec<u16>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_U16-{}", transcoder_name, name))
        }
        // encode as i16 values
        (min, max) if min >= i16::MIN as f64 && max <= i16::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<i16>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_I16-{}", transcoder_name, name))
        }
        // encode as u32 values
        (min, max) if min >= 0.0 && max <= u32::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<u32>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_U32-{}", transcoder_name, name))
        }
        // encode as i32 values
        (min, max) if min >= i32::MIN as f64 && max <= i32::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<i32>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_I32-{}", transcoder_name, name))
        }
        (_, _) => unreachable!(
            "float column not byte trimmable: range [{:?}, {:?}]",
            min, max
        ),
    };
    FloatEncoding::F64(enc, name)
}
// Convert float data to byte-trimmed integers and potentially RLE. It is the
// caller's responsibility to ensure all data are natural numbers that can be
// round tripped from float to int and back without loss of precision.
Convert float data to byte-trimmed integers and potentially RLE. It is the
caller's responsibility to ensure all data are natural numbers that can be
round tripped from float to int and back without loss of precision.
Convert float data to byte - trimmed integers and potentially RLE . It is the caller ' s responsibility to ensure all data are natural numbers that can be round tripped from float to int and back without loss of precision .
fn from_slice_with_byte_trimming(arr: &[f64], range: (f64, f64)) -> FloatEncoding {
    // determine min and max values.
    let min = range.0;
    let max = range.1;
    // If true then use RLE after byte trimming.
    let rle = should_rle_from_iter(arr.len(), arr.iter().map(Some));
    // This match is carefully ordered. It prioritises smaller physical
    // datatypes that can correctly represent the provided logical data.
    let transcoder = FloatByteTrimmer {};
    let transcoder_name = format!("{}", &transcoder);
    let (enc, name) = match (min, max) {
        // encode as u8 values
        (min, max) if min >= 0.0 && max <= u8::MAX as f64 => {
            let arr = arr
                .iter()
                .map::<u8, _>(|v| transcoder.encode(*v))
                .collect::<Vec<_>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_U8-{}", transcoder_name, name))
        }
        // encode as i8 values
        (min, max) if min >= i8::MIN as f64 && max <= i8::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<i8>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_I8-{}", transcoder_name, name))
        }
        // encode as u16 values
        (min, max) if min >= 0.0 && max <= u16::MAX as f64 => {
            let arr = arr
                .iter()
                .map::<u16, _>(|v| transcoder.encode(*v))
                .collect::<Vec<u16>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_U16-{}", transcoder_name, name))
        }
        // encode as i16 values
        (min, max) if min >= i16::MIN as f64 && max <= i16::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<i16>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_I16-{}", transcoder_name, name))
        }
        // encode as u32 values
        (min, max) if min >= 0.0 && max <= u32::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<u32>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_U32-{}", transcoder_name, name))
        }
        // encode as i32 values
        (min, max) if min >= i32::MIN as f64 && max <= i32::MAX as f64 => {
            let arr = arr
                .iter()
                .map(|v| transcoder.encode(*v))
                .collect::<Vec<i32>>();
            let enc: Box<dyn ScalarEncoding<f64>> = if rle {
                Box::new(RLE::new_from_iter(arr.into_iter(), transcoder))
            } else {
                Box::new(Fixed::new(arr, transcoder))
            };
            let name = enc.name();
            (enc, format!("{}_I32-{}", transcoder_name, name))
        }
        (_, _) => unreachable!(
            "float column not byte trimmable: range [{:?}, {:?}]",
            min, max
        ),
    };
    FloatEncoding::F64(enc, name)
}
fn from_slice_with_byte_trimming ( arr : & [ f64 ] , range : ( f64 , f64 ) ) -> FloatEncoding { // determine min and max values. let min = range . 0 ; let max = range . 1 ; // If true then use RLE after byte trimming. let rle = should_rle_from_iter ( arr . len ( ) , arr . iter ( ) . map ( Some ) ) ; // This match is carefully ordered. It prioritises smaller physical // datatypes that can correctly represent the provided logical data. let transcoder = FloatByteTrimmer { } ; let transcoder_name = format ! ( " " transcoder ) ; let ( enc , name ) = match ( min , max ) { // encode as u8 values ( min , max ) if min >= 0.0 && max <= u8 :: MAX as f64 => { let arr = arr . iter ( ) . map :: < u8 , _ > ( | v | transcoder . encode ( * v ) ) . collect :: < Vec < _ > > ( ) ; let enc : Box < dyn ScalarEncoding < f64 > > = if rle { Box :: new ( RLE :: new_from_iter ( arr . into_iter ( ) , transcoder ) ) } else { Box :: new ( Fixed :: new ( arr , transcoder ) ) } ; let name = enc . name ( ) ; ( enc , format ! ( " " transcoder_name name ) ) } // encode as i8 values ( min , max ) if min >= i8 :: MIN as f64 && max <= i8 :: MAX as f64 => { let arr = arr . iter ( ) . map ( | v | transcoder . encode ( * v ) ) . collect :: < Vec < i8 > > ( ) ; let enc : Box < dyn ScalarEncoding < f64 > > = if rle { Box :: new ( RLE :: new_from_iter ( arr . into_iter ( ) , transcoder ) ) } else { Box :: new ( Fixed :: new ( arr , transcoder ) ) } ; let name = enc . name ( ) ; ( enc , format ! ( " " transcoder_name name ) ) } // encode as u16 values ( min , max ) if min >= 0.0 && max <= u16 :: MAX as f64 => { let arr = arr . iter ( ) . map :: < u16 , _ > ( | v | transcoder . encode ( * v ) ) . collect :: < Vec < u16 > > ( ) ; let enc : Box < dyn ScalarEncoding < f64 > > = if rle { Box :: new ( RLE :: new_from_iter ( arr . into_iter ( ) , transcoder ) ) } else { Box :: new ( Fixed :: new ( arr , transcoder ) ) } ; let name = enc . name ( ) ; ( enc , format ! ( " " transcoder_name name ) ) } // encode as i16 values ( min , max ) if min >= i16 :: MIN as f64 && max <= i16 :: MAX as f64 => { let arr = arr . iter ( ) . map ( | v | transcoder . encode ( * v ) ) . collect :: < Vec < i16 > > ( ) ; let enc : Box < dyn ScalarEncoding < f64 > > = if rle { Box :: new ( RLE :: new_from_iter ( arr . into_iter ( ) , transcoder ) ) } else { Box :: new ( Fixed :: new ( arr , transcoder ) ) } ; let name = enc . name ( ) ; ( enc , format ! ( " " transcoder_name name ) ) } // encode as u32 values ( min , max ) if min >= 0.0 && max <= u32 :: MAX as f64 => { let arr = arr . iter ( ) . map ( | v | transcoder . encode ( * v ) ) . collect :: < Vec < u32 > > ( ) ; let enc : Box < dyn ScalarEncoding < f64 > > = if rle { Box :: new ( RLE :: new_from_iter ( arr . into_iter ( ) , transcoder ) ) } else { Box :: new ( Fixed :: new ( arr , transcoder ) ) } ; let name = enc . name ( ) ; ( enc , format ! ( " " transcoder_name name ) ) } // encode as i32 values ( min , max ) if min >= i32 :: MIN as f64 && max <= i32 :: MAX as f64 => { let arr = arr . iter ( ) . map ( | v | transcoder . encode ( * v ) ) . collect :: < Vec < i32 > > ( ) ; let enc : Box < dyn ScalarEncoding < f64 > > = if rle { Box :: new ( RLE :: new_from_iter ( arr . into_iter ( ) , transcoder ) ) } else { Box :: new ( Fixed :: new ( arr , transcoder ) ) } ; let name = enc . name ( ) ; ( enc , format ! ( " " transcoder_name name ) ) } ( _ , _ ) => unreachable ! ( " " min max ) , } ; FloatEncoding :: F64 ( enc , name ) }
Convert float data to byte-trimmed integers and potentially RLE.
Convert float data to byte - trimmed integers and potentially RLE .
arr
&[f64]
range
(f64, f64)
arr
&[f64]
range
(f64, f64)