MCPcopy Create free account
hub / github.com/apache/datafusion / hash_string_view_array_inner

Function hash_string_view_array_inner

datafusion/common/src/hash_utils.rs:312–366  ·  view source on GitHub ↗
(
    array: &GenericByteViewArray<T>,
    random_state: &RandomState,
    hashes_buffer: &mut [u64],
)

Source from the content-addressed store, hash-verified

310#[cfg(not(feature = "force_hash_collisions"))]
311#[inline(never)]
312fn hash_string_view_array_inner<
313 T: ByteViewType,
314 const HAS_NULLS: bool,
315 const HAS_BUFFERS: bool,
316 const REHASH: bool,
317>(
318 array: &GenericByteViewArray<T>,
319 random_state: &RandomState,
320 hashes_buffer: &mut [u64],
321) {
322 assert_eq!(
323 hashes_buffer.len(),
324 array.len(),
325 "hashes_buffer and array should be of equal length"
326 );
327
328 let buffers = array.data_buffers();
329 let view_bytes = |view_len: u32, view: u128| {
330 let view = ByteView::from(view);
331 let offset = view.offset as usize;
332 // SAFETY: view is a valid view as it came from the array
333 unsafe {
334 let data = buffers.get_unchecked(view.buffer_index as usize);
335 data.get_unchecked(offset..offset + view_len as usize)
336 }
337 };
338
339 let hashes_and_views = hashes_buffer.iter_mut().zip(array.views().iter());
340 for (i, (hash, &v)) in hashes_and_views.enumerate() {
341 if HAS_NULLS && array.is_null(i) {
342 continue;
343 }
344 let view_len = v as u32;
345 // all views are inlined, no need to access external buffers
346 if !HAS_BUFFERS || view_len <= 12 {
347 if REHASH {
348 let mut hasher = seeded_state(*hash).build_hasher();
349 v.hash_write(&mut hasher);
350 *hash = hasher.finish();
351 } else {
352 *hash = v.hash_one(random_state);
353 }
354 continue;
355 }
356 // view is not inlined, so we need to hash the bytes as well
357 let value = view_bytes(view_len, v);
358 if REHASH {
359 let mut hasher = seeded_state(*hash).build_hasher();
360 value.hash_write(&mut hasher);
361 *hash = hasher.finish();
362 } else {
363 *hash = value.hash_one(random_state);
364 }
365 }
366}
367
368/// Builds hash values for array views and writes them into `hashes_buffer`
369/// If `rehash==true` this combines the previous hash value in the buffer

Callers

nothing calls this directly

Calls 6

seeded_stateFunction · 0.85
hash_writeMethod · 0.80
hash_oneMethod · 0.80
iterMethod · 0.45
is_nullMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…