|
1 |
| -use crate::chunker::dynamicChunker::DynamicChunker; |
2 | 1 | use crate::chunker::fileChunker::FileChunker;
|
| 2 | +use crate::chunker::rabinChunker::RabinChunker; |
3 | 3 | use crate::chunker::staticChunker::StaticChunker;
|
4 |
| -use std::slice::Chunks; |
5 | 4 |
|
6 | 5 | use clap::ValueEnum;
|
7 | 6 | use memmap2::Mmap;
|
8 | 7 |
|
| 8 | +#[derive(Debug, Clone, Copy)] |
| 9 | +pub enum ChunkingScheme { |
| 10 | + FILE, |
| 11 | + STATIC, |
| 12 | + CONTENT, |
| 13 | +} |
| 14 | + |
9 | 15 | #[derive(ValueEnum, Clone, Copy, Debug)]
|
10 | 16 | pub enum ChunkerType {
|
11 | 17 | FILE,
|
@@ -45,42 +51,46 @@ impl ChunkerType {
|
45 | 51 | ChunkerType::CDC64K => 1 << 16,
|
46 | 52 | }
|
47 | 53 | }
|
48 |
| -} |
49 |
| - |
50 |
| -pub trait Chunker { |
51 |
| - fn chunk<'a>(&self, mmap: &'a Mmap) -> Chunks<'a, u8>; |
52 |
| -} |
53 |
| - |
54 |
| -pub struct ChunkFactory { |
55 |
| - t: ChunkerType, |
56 |
| - s: Option<Box<str>>, |
57 |
| -} |
58 |
| - |
59 |
| -impl ChunkFactory { |
60 |
| - pub fn new(chunkerType: ChunkerType, salt: Option<Box<str>>) -> Self { |
61 |
| - Self { |
62 |
| - t: chunkerType, |
63 |
| - s: salt, |
64 |
| - } |
65 |
| - } |
66 | 54 |
|
67 |
| - pub fn createChunker(&self) -> Box<dyn Chunker> { |
68 |
| - match self.t { |
69 |
| - ChunkerType::FILE => Box::new(FileChunker::new()), |
| 55 | + pub fn getScheme(&self) -> ChunkingScheme { |
| 56 | + match self { |
| 57 | + ChunkerType::FILE => ChunkingScheme::FILE, |
70 | 58 | ChunkerType::SC1K
|
71 | 59 | | ChunkerType::SC2K
|
72 | 60 | | ChunkerType::SC4K
|
73 | 61 | | ChunkerType::SC8K
|
74 | 62 | | ChunkerType::SC16K
|
75 | 63 | | ChunkerType::SC32K
|
76 |
| - | ChunkerType::SC64K => Box::new(StaticChunker::new(ChunkerType::getSize(&self.t))), |
| 64 | + | ChunkerType::SC64K => ChunkingScheme::STATIC, |
77 | 65 | ChunkerType::CDC1K
|
78 | 66 | | ChunkerType::CDC2K
|
79 | 67 | | ChunkerType::CDC4K
|
80 | 68 | | ChunkerType::CDC8K
|
81 | 69 | | ChunkerType::CDC16K
|
82 | 70 | | ChunkerType::CDC32K
|
83 |
| - | ChunkerType::CDC64K => Box::new(DynamicChunker::new(ChunkerType::getSize(&self.t))), |
| 71 | + | ChunkerType::CDC64K => ChunkingScheme::CONTENT, |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +pub trait Chunker { |
| 77 | + fn chunk<'a>(&self, mmap: &'a Mmap) -> Box<dyn Iterator<Item = &'a [u8]> + 'a>; |
| 78 | +} |
| 79 | + |
| 80 | +pub struct ChunkFactory { |
| 81 | + t: ChunkerType, |
| 82 | +} |
| 83 | + |
| 84 | +impl ChunkFactory { |
| 85 | + pub fn new(chunkerType: ChunkerType) -> Self { |
| 86 | + Self { t: chunkerType } |
| 87 | + } |
| 88 | + |
| 89 | + pub fn createChunker(&self) -> Box<dyn Chunker> { |
| 90 | + match self.t.getScheme() { |
| 91 | + ChunkingScheme::FILE => Box::new(FileChunker::new()), |
| 92 | + ChunkingScheme::STATIC => Box::new(StaticChunker::new(self.t.getSize())), |
| 93 | + ChunkingScheme::CONTENT => Box::new(RabinChunker::<64>::new(self.t.getSize())), |
84 | 94 | }
|
85 | 95 | }
|
86 | 96 | }
|
0 commit comments