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

Method insert

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

Insert a hash into the table, returning its index. If the hash is already in the table, returns its existing index without inserting a duplicate (idempotent operation). # Arguments `hash` - The 32-byte Blake3 hash to insert. # Returns The `HashIndex` for this hash (either newly assigned or existing). # Errors - [`FormatError::HashTableFull`] if the table already has [`MAX_HASH_TABLE_ENTRIES

(&mut self, hash: [u8; 32])

Source from the content-addressed store, hash-verified

265 /// assert_eq!(table.len(), 2); // self + 1 dep
266 /// ```
267 pub fn insert(&mut self, hash: [u8; 32]) -> FormatResult<HashIndex> {
268 if let Some(&existing) = self.index_map.get(&hash) {
269 return Ok(existing);
270 }
271
272 if self.hashes.len() >= MAX_HASH_TABLE_ENTRIES {
273 return Err(FormatError::HashTableFull);
274 }
275
276 let index = self.hashes.len() as HashIndex;
277 self.hashes.push(hash);
278 self.index_map.insert(hash, index);
279 Ok(index)
280 }
281
282 /// Look up the index for a given hash.
283 ///

Callers 15

walk_backwardMethod · 0.45
newMethod · 0.45
from_hashesMethod · 0.45
mergeMethod · 0.45
test_insert_new_hashFunction · 0.45
test_insert_idempotentFunction · 0.45
test_lookup_existingFunction · 0.45
test_iter_orderFunction · 0.45

Calls 3

getMethod · 0.65
lenMethod · 0.45
pushMethod · 0.45

Tested by 15

test_insert_new_hashFunction · 0.36
test_insert_idempotentFunction · 0.36
test_lookup_existingFunction · 0.36
test_iter_orderFunction · 0.36
test_stats_with_entriesFunction · 0.36
test_display_formatFunction · 0.36