chunk_diff/hasher/
mod.rs

1pub mod xxhash;
2
3use rayon::prelude::{IndexedParallelIterator, ParallelIterator, ParallelSlice};
4
5use crate::util::{chunk::Chunk, rect::Rect};
6
7pub trait Hasher {
8    fn hash(&self, data: &[u8]) -> u64;
9
10    fn hash_rect(&self, data: &[u8], chunk: &Chunk, full: &Rect) -> Vec<u64>
11    where
12        Self: Sync,
13    {
14        let point = chunk.point();
15        let rect = chunk.rect();
16
17        data.par_chunks(full.width())
18            .skip(point.y())
19            .take(rect.height())
20            .map(|slice| &slice[point.x()..point.x() + rect.width()])
21            .map(|slice| self.hash(slice))
22            .collect::<Vec<_>>()
23    }
24}