MCPcopy Create free account
hub / github.com/hashintel/hash / intern_slice

Method intern_slice

libs/@local/hashql/core/src/intern/set.rs:389–417  ·  view source on GitHub ↗

Interns a slice of values into the set. This method is similar to `intern` but works with slices. It ensures that only one copy of a slice with identical content exists in memory. # Type Constraints - `T` must be `Debug + Copy + Eq + Hash` - `T` must not be a zero-sized type - `T` must not implement `Drop` # Examples Basic usage: ``` # use hashql_core::{heap::Heap, intern::InternSet}; let he

(&self, value: &[T])

Source from the content-addressed store, hash-verified

387 /// let interned = interner.intern_slice(slice);
388 /// ```
389 pub fn intern_slice(&self, value: &[T]) -> Interned<'heap, [T]> {
390 const { Self::ASSERT_T_IS_NOT_DROP };
391 const { Self::ASSERT_T_IS_NOT_ZERO_SIZED };
392
393 if value.is_empty() {
394 return Interned::empty();
395 }
396
397 let heap = self.heap;
398
399 let value = self.inner.map(|inner| {
400 let hash_value = inner.hasher().hash_one(value);
401
402 match inner
403 .raw_entry_mut()
404 .from_key_hashed_nocheck(hash_value, value)
405 {
406 RawEntryMut::Vacant(entry) => {
407 let value = value.transfer_into(heap);
408
409 let (key, ()) = entry.insert_hashed_nocheck(hash_value, &*value, ());
410 *key
411 }
412 RawEntryMut::Occupied(entry) => *entry.key(),
413 }
414 });
415
416 Interned::new_unchecked(value)
417 }
418}
419
420#[cfg(test)]

Callers 15

intern_itemsMethod · 0.80
finishMethod · 0.80
finish_no_modificationsFunction · 0.80
finish_modificationsFunction · 0.80
mapFunction · 0.80
map_repeatFunction · 0.80
map_edge_casesFunction · 0.80
try_map_successFunction · 0.80
try_map_failureFunction · 0.80
try_map_with_optionFunction · 0.80

Calls 4

transfer_intoMethod · 0.80
emptyFunction · 0.50
is_emptyMethod · 0.45
mapMethod · 0.45

Tested by 15

finish_no_modificationsFunction · 0.64
finish_modificationsFunction · 0.64
mapFunction · 0.64
map_edge_casesFunction · 0.64
try_map_successFunction · 0.64
try_map_failureFunction · 0.64
try_map_multiple_callsFunction · 0.64
try_map_last_elementFunction · 0.64
try_scan_emptyFunction · 0.64
try_scan_cumulative_sumFunction · 0.64