rdedup_cdc/lib.rs
1#![cfg_attr(feature = "bench", feature(test))]
2
3#[cfg(test)]
4extern crate rand;
5
6#[cfg(feature = "bench")]
7extern crate test;
8
9/// Rolling sum and chunk splitting used by
10/// `bup` - https://github.com/bup/bup/
11pub mod bup;
12pub use bup::Bup;
13
14pub mod gear;
15pub use gear::Gear;
16
17pub mod fastcdc;
18pub use fastcdc::FastCDC;
19
20/// Rolling sum engine trait
21pub trait RollingHash {
22 type Digest;
23
24 fn roll_byte(&mut self, buf: u8);
25
26 /// Roll over a slice of bytes
27 fn roll(&mut self, buf: &[u8]) {
28 buf.iter().map(|&b| self.roll_byte(b)).count();
29 }
30
31 /// Return current rolling sum digest
32 fn digest(&self) -> Self::Digest;
33
34 /// Resets the internal state
35 fn reset(&mut self);
36}
37
38pub trait CDC {
39 /// Find the end of the chunk.
40 ///
41 /// When edge is find, state of CDC should automatically be reset.
42 ///
43 /// Returns:
44 ///
45 /// * None - no chunk split was found, and the whole `buf` belongs
46 /// to the current chunk.
47 /// * Some - chunk edge was found, and it is splitting the `buf`
48 /// in two pieces. The second one has not yet been searched
49 /// for more chunks.
50 fn find_chunk<'a>(&mut self, buf: &'a [u8]) -> Option<(&'a [u8], &'a [u8])>;
51}
52
53#[cfg(test)]
54mod tests;