summary refs log tree commit diff
path: root/ripple
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-05-01 18:03:33 +0000
committeredef <edef@unfathomable.blue>2022-05-01 18:03:33 +0000
commit224960514330d8f9f7e21196935eb9c7f0446b10 (patch)
tree512c086948377622a2f04b1a21ff46c8cbac63f6 /ripple
parentd9ea1f645cdb855d6713b62bb533c3f6c86619c5 (diff)
downloadunf-legacy-224960514330d8f9f7e21196935eb9c7f0446b10.tar.zst
ripple/fossil/chunker: DRY out WINDOW_SIZE
Change-Id: Ib5a0bc2fb5b725dfe1f7f4557838529711407203
Diffstat (limited to 'ripple')
-rw-r--r--ripple/fossil/src/chunker/mod.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/ripple/fossil/src/chunker/mod.rs b/ripple/fossil/src/chunker/mod.rs
index c2a9f4c..638b6fa 100644
--- a/ripple/fossil/src/chunker/mod.rs
+++ b/ripple/fossil/src/chunker/mod.rs
@@ -5,6 +5,7 @@ use std::mem;
 
 mod buz;
 
+const WINDOW_SIZE: usize = 48;
 pub const MIN_CHUNK_SIZE: usize = AVG_CHUNK_SIZE / 4;
 pub const AVG_CHUNK_SIZE: usize = 64 * 1024;
 pub const MAX_CHUNK_SIZE: usize = AVG_CHUNK_SIZE * 4;
@@ -44,7 +45,7 @@ impl<'a> Iterator for Chunker<'a> {
 			.skip(MIN_CHUNK_SIZE);
 
 		let d = discriminator_from_average(AVG_CHUNK_SIZE as u64);
-		let mut hasher = buz::Rolling::<48>::from_slice(&self.buffer[..MIN_CHUNK_SIZE]);
+		let mut hasher = buz::Rolling::<WINDOW_SIZE>::from_slice(&self.buffer[..MIN_CHUNK_SIZE]);
 		let chunk;
 		for (idx, byte) in bytes {
 			let buz::Hash(x) = hasher.sum();
@@ -175,16 +176,16 @@ mod test {
 	fn min_chunk() {
 		let data = generate(1024 * 32);
 
-		// a "tail" is a 48-byte sequence that terminates a chunk
-		// we extract one from our test vectors, since every chunk
-		// smaller than MAX_CHUNK_SIZE ends in a tail
-		let mut tail = [0; 48];
+		// a "tail" is a window-sized byte sequence that terminates a chunk
+		// we extract one from our test vectors, since every chunk smaller
+		// than MAX_CHUNK_SIZE ends in a tail
+		let mut tail = [0; super::WINDOW_SIZE];
 		tail.copy_from_slice({
 			let chunk = super::Chunker::from(&data).next().unwrap();
-			chunk.rchunks_exact(48).next().unwrap()
+			chunk.rchunks_exact(super::WINDOW_SIZE).next().unwrap()
 		});
 
-		let mut data = vec![0; super::MIN_CHUNK_SIZE - 48];
+		let mut data = vec![0; super::MIN_CHUNK_SIZE - super::WINDOW_SIZE];
 		data.extend(tail);
 		data.push(0);