/// Adds the specified number of bytes to the bit count, which is a tuple where
/// the first element is the high order value. panic!() if this would cause
/// numeric overflow.
Adds the specified number of bytes to the bit count, which is a tuple where
the first element is the high order value. panic!() if this would cause
numeric overflow.
Adds the specified number of bytes to the bit count which is a tuple where the first element is the high order value . panic! () if this would cause numeric overflow .
pub fn add_bytes_to_bits_tuple(bits: (u64, u64), bytes: u64) -> (u64, u64) {
    let (new_high_bits, new_low_bits) = to_bits(bytes);
    let (hi, low) = bits;
    // Add the low order value - if there is no overflow, then add the high
    // order values. If the addition of the low order values causes overflow,
    // add one to the high order values before adding them.
    match low.checked_add(new_low_bits) {
        Some(x) => {
            if new_high_bits == 0 {
                // This is the fast path - every other alternative will rarely
                // occur in practice considering how large an input would need
                // to be for those paths to be used.
                (hi, x)
            } else {
                match hi.checked_add(new_high_bits) {
                    Some(y) => (y, x),
                    None => panic!("Numeric overflow occured."),
                }
            }
        },
        None => {
            let z = match new_high_bits.checked_add(1) {
                Some(w) => w,
                None => panic!("Numeric overflow occured."),
            };
            match hi.checked_add(z) {
                // This re-executes the addition that was already performed
                // earlier when overflow occured, this time allowing the
                // overflow to happen. Technically, this could be avoided by
                // using the checked add intrinsic directly, but that involves
                // using unsafe code and is not really worthwhile considering
                // how infrequently code will run in practice. This is the
                // reason that this function requires that the type T be
                // UnsignedInt - overflow is not defined for Signed types.
                // This function could be implemented for signed types as well
                // if that were needed.
                Some(y) => (y, low.wrapping_add(new_low_bits)),
                None => panic!("Numeric overflow occured."),
            }
        },
    }
}
pub fn add_bytes_to_bits_tuple ( bits : ( u64 , u64 ) , bytes : u64 ) -> ( u64 , u64 ) { let ( new_high_bits , new_low_bits ) = to_bits ( bytes ) ; let ( hi , low ) = bits ; // Add the low order value - if there is no overflow, then add the high // order values. If the addition of the low order values causes overflow, // add one to the high order values before adding them. match low . checked_add ( new_low_bits ) { Some ( x ) => { if new_high_bits == 0 { // This is the fast path - every other alternative will rarely // occur in practice considering how large an input would need // to be for those paths to be used. ( hi , x ) } else { match hi . checked_add ( new_high_bits ) { Some ( y ) => ( y , x ) , None => panic ! ( " " ) , } } } , None => { let z = match new_high_bits . checked_add ( 1 ) { Some ( w ) => w , None => panic ! ( " " ) , } ; match hi . checked_add ( z ) { // This re-executes the addition that was already performed // earlier when overflow occured, this time allowing the // overflow to happen. Technically, this could be avoided by // using the checked add intrinsic directly, but that involves // using unsafe code and is not really worthwhile considering // how infrequently code will run in practice. This is the // reason that this function requires that the type T be // UnsignedInt - overflow is not defined for Signed types. // This function could be implemented for signed types as well // if that were needed. Some ( y ) => ( y , low . wrapping_add ( new_low_bits ) ) , None => panic ! ( " " ) , } } , } }
Adds the specified number of bytes to the bit count, which is a tuple where
the first element is the high order value.
Adds the specified number of bytes to the bit count which is a tuple where the first element is the high order value .
bits
(u64, u64)
bytes
u64