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])
| 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 | /// |