src/backup/chunker.rs: change window size back to 48

Using 64 is a bad idea, because it always computes hash 0 for
constant data streams.
This commit is contained in:
Dietmar Maurer 2019-02-20 11:01:09 +01:00
parent 247cdbce72
commit 1b9c959c32
1 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,7 @@
const CA_CHUNKER_WINDOW_SIZE: usize = 64;
/// Note: doö not use 32 or 64, because that always computes hash 0
/// for constant data streams .. 0,0,0,0,0,0
const CA_CHUNKER_WINDOW_SIZE: usize = 48;
/// Slinding window chunker (Buzhash) /// Slinding window chunker (Buzhash)
/// ///
@ -161,16 +164,14 @@ impl Chunker {
self.start(); self.start();
} }
//let mut idx = self.chunk_size % CA_CHUNKER_WINDOW_SIZE; let mut idx = self.chunk_size % CA_CHUNKER_WINDOW_SIZE;
let mut idx = self.chunk_size & 0x3f;
while pos < data_len { while pos < data_len {
// roll window // roll window
let enter = data[pos]; let enter = data[pos];
let leave = self.window[idx]; let leave = self.window[idx];
self.h = self.h.rotate_left(1) ^ self.h = self.h.rotate_left(1) ^
//BUZHASH_TABLE[leave as usize].rotate_left(CA_CHUNKER_WINDOW_SIZE as u32) ^ BUZHASH_TABLE[leave as usize].rotate_left(CA_CHUNKER_WINDOW_SIZE as u32) ^
BUZHASH_TABLE[leave as usize] ^
BUZHASH_TABLE[enter as usize]; BUZHASH_TABLE[enter as usize];
self.chunk_size += 1; self.chunk_size += 1;
@ -185,8 +186,7 @@ impl Chunker {
return pos; return pos;
} }
//idx = self.chunk_size % CA_CHUNKER_WINDOW_SIZE; idx = self.chunk_size % CA_CHUNKER_WINDOW_SIZE;
idx = self.chunk_size & 0x3f;
//idx += 1; if idx >= CA_CHUNKER_WINDOW_SIZE { idx = 0 }; //idx += 1; if idx >= CA_CHUNKER_WINDOW_SIZE { idx = 0 };
} }