use std::io::Read;
use crate::util::hints::{likely, unlikely};
use super::{DEFAULT_RAPID_SECRETS, RapidSecrets, RapidStreamHasherInlineV3};
#[inline]
pub fn rapidhash_v3_file<R: Read>(data: R) -> std::io::Result<u64> {
rapidhash_v3_file_inline::<R, false>(data, &DEFAULT_RAPID_SECRETS)
}
#[inline]
pub fn rapidhash_v3_file_seeded<R: Read>(data: R, secrets: &RapidSecrets) -> std::io::Result<u64> {
rapidhash_v3_file_inline::<R, false>(data, secrets)
}
#[inline(always)]
pub fn rapidhash_v3_file_inline<R: Read, const PROTECTED: bool>(mut data: R, secrets: &RapidSecrets) -> std::io::Result<u64> {
let mut hasher = RapidStreamHasherInlineV3::<true, PROTECTED>::new(secrets);
let mut buf = [0u8; 8 * 1024]; let mut pos = 0;
loop {
let n = data.read(&mut buf[pos..])?;
pos += n;
if likely(n > 0 && pos < buf.len()) {
continue;
}
hasher.write(&buf[..pos]);
if unlikely(n == 0) {
break;
}
pos = 0;
}
Ok(hasher.finish())
}
#[cfg(test)]
mod tests {
use std::io::{Seek, SeekFrom, Write};
use crate::util::macros::compare_rapidhash_file;
use crate::v3::rapidhash_v3_inline;
use super::*;
compare_rapidhash_file!(compare_rapidhash_v1_file, rapidhash_v3_inline::<true, false, false>, rapidhash_v3_file_inline::<_, false>);
}