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

Method from_hashes

atomic-core/src/change/format_v3/hash_table.rs:217–233  ·  view source on GitHub ↗

Reconstruct a dedup table from a list of hashes (read from a file). The first hash in the list is assumed to be the change's own hash (index 0). The order of hashes in the vector determines their indices. # Arguments `hashes` - Ordered list of 32-byte hashes as read from the file. # Errors - [`FormatError::HashTableFull`] if there are more than [`MAX_HASH_TABLE_ENTRIES`] hashes. - [`FormatErr

(hashes: Vec<[u8; 32]>)

Source from the content-addressed store, hash-verified

215 /// assert_eq!(table.resolve(1).unwrap(), &h1);
216 /// ```
217 pub fn from_hashes(hashes: Vec<[u8; 32]>) -> FormatResult<Self> {
218 if hashes.len() > MAX_HASH_TABLE_ENTRIES {
219 return Err(FormatError::HashTableFull);
220 }
221
222 let mut index_map = HashMap::with_capacity(hashes.len());
223 for (i, hash) in hashes.iter().enumerate() {
224 let index = i as HashIndex;
225 if index_map.insert(*hash, index).is_some() {
226 return Err(FormatError::InvalidHeader {
227 reason: format!("duplicate hash in dedup table at index {}", i),
228 });
229 }
230 }
231
232 Ok(Self { hashes, index_map })
233 }
234
235 /// Insert a hash into the table, returning its index.
236 ///

Callers

nothing calls this directly

Calls 3

lenMethod · 0.45
iterMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected