use super::*;
use std::borrow::Cow;
impl<E: Environment, const NUM_WINDOWS: u8, const WINDOW_SIZE: u8> HashUncompressed
for BHPHasher<E, NUM_WINDOWS, WINDOW_SIZE>
{
type Input = bool;
type Output = Group<E>;
fn hash_uncompressed(&self, input: &[Self::Input]) -> Result<Self::Output> {
ensure!(input.len() > Self::MIN_BITS, "Inputs to this BHP must be greater than {} bits", Self::MIN_BITS);
ensure!(
input.len() <= Self::MAX_BITS,
"Inputs to this BHP cannot exceed {} bits, found {}",
Self::MAX_BITS,
input.len()
);
let input = if input.len() % BHP_CHUNK_SIZE != 0 {
let padding = BHP_CHUNK_SIZE - (input.len() % BHP_CHUNK_SIZE);
let mut padded_input = vec![false; input.len() + padding];
padded_input[..input.len()].copy_from_slice(input);
ensure!((padded_input.len() % BHP_CHUNK_SIZE) == 0, "Input must be a multiple of {BHP_CHUNK_SIZE}");
Cow::Owned(padded_input)
} else {
Cow::Borrowed(input)
};
Ok(input
.chunks(WINDOW_SIZE as usize * BHP_CHUNK_SIZE)
.zip(&*self.bases_lookup)
.flat_map(|(bits, bases)| {
bits.chunks(BHP_CHUNK_SIZE).zip(bases).map(|(chunk_bits, base)| {
base[(chunk_bits[0] as usize) | (chunk_bits[1] as usize) << 1 | (chunk_bits[2] as usize) << 2]
})
})
.sum())
}
}