use super::Exception;
use crate::{
bitpack::bitpack_encoded, delta::in_place_deltas, float::AlpFloat, params::pack_params,
};
#[inline(always)]
#[allow(clippy::too_many_arguments)]
pub fn encode_delta<F: AlpFloat>(
count: u16,
exp: u8,
fac: u8,
use_div: bool,
encoded_ints: &mut [F::Int],
min_delta: F::Int,
delta_bit_width: u8,
exceptions: &[Exception<F::RawBits>],
dst: &mut Vec<u8>,
) {
let first = encoded_ints[0];
let count_bytes = count.to_le_bytes();
let params_bytes = pack_params(exp, fac, delta_bit_width).to_le_bytes();
let type_byte = if use_div {
F::TYPE_DEC_DELTA_BYTE
} else {
F::TYPE_DELTA_BYTE
};
let header = [
type_byte,
count_bytes[0],
count_bytes[1],
params_bytes[0],
params_bytes[1],
];
dst.extend_from_slice(&header);
F::write_base(first, dst);
F::write_base(min_delta, dst);
if delta_bit_width > 0 && encoded_ints.len() > 1 {
in_place_deltas::<F>(encoded_ints);
bitpack_encoded::<F>(&encoded_ints[1..], min_delta, delta_bit_width, dst);
}
if !exceptions.is_empty() {
let exc_count = exceptions.len() as u16;
dst.extend_from_slice(&exc_count.to_le_bytes());
for exc in exceptions {
F::write_exception(exc.pos, exc.bits, dst);
}
}
}