MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / compute

Method compute

atomic-remote/src/streaming/negotiation.rs:95–120  ·  view source on GitHub ↗

Compute the negotiation result from a manifest and a "have" list. The "have" list is a set of chunk hashes that the receiver already possesses. Any chunk in the manifest whose hash matches a "have" entry is skipped — only the remaining chunks need to be transferred. # Arguments `manifest` - The full chunk manifest of the change. `have_hashes` - Chunk hashes the receiver already has. # Returns

(manifest: &ChunkManifest, have_hashes: &[[u8; 32]])

Source from the content-addressed store, hash-verified

93 ///
94 /// A `ChunkNegotiation` describing what still needs to be transferred.
95 pub fn compute(manifest: &ChunkManifest, have_hashes: &[[u8; 32]]) -> Self {
96 let have_set: HashSet<[u8; 32]> = have_hashes.iter().copied().collect();
97
98 let mut needed = Vec::new();
99 let mut already_have = 0usize;
100 let mut bytes_saved = 0u64;
101 let mut bytes_needed = 0u64;
102
103 for entry in &manifest.entries {
104 if have_set.contains(&entry.hash) {
105 already_have += 1;
106 bytes_saved += entry.compressed_size as u64;
107 } else {
108 bytes_needed += entry.compressed_size as u64;
109 needed.push(*entry);
110 }
111 }
112
113 Self {
114 needed,
115 already_have,
116 bytes_saved,
117 bytes_needed,
118 total_chunks: manifest.chunk_count(),
119 }
120 }
121
122 /// Returns `true` if all chunks are already present (nothing to transfer).
123 pub fn is_complete(&self) -> bool {

Callers

nothing calls this directly

Calls 4

chunk_countMethod · 0.80
iterMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected