Path: blob/main/crates/polars-compute/src/gather/bitmap.rs
6939 views
use arrow::array::Array;1use arrow::bitmap::Bitmap;2use arrow::datatypes::IdxArr;3use polars_utils::IdxSize;45/// # Safety6/// Doesn't do any bound checks.7pub unsafe fn take_bitmap_unchecked(values: &Bitmap, indices: &[IdxSize]) -> Bitmap {8let values = indices.iter().map(|&index| {9debug_assert!((index as usize) < values.len());10values.get_bit_unchecked(index as usize)11});12Bitmap::from_trusted_len_iter(values)13}1415/// # Safety16/// Doesn't check bounds for non-null elements.17pub unsafe fn take_bitmap_nulls_unchecked(values: &Bitmap, indices: &IdxArr) -> Bitmap {18// Fast-path: no need to bother with null indices.19if indices.null_count() == 0 {20return take_bitmap_unchecked(values, indices.values());21}2223if values.is_empty() {24// Nothing can be in-bounds, assume indices is full-null.25debug_assert!(indices.null_count() == indices.len());26return Bitmap::new_zeroed(indices.len());27}2829let values = indices.iter().map(|opt_index| {30// We checked that values.len() > 0 so we can use index 0 for nulls.31let index = opt_index.copied().unwrap_or(0) as usize;32debug_assert!(index < values.len());33values.get_bit_unchecked(index)34});35Bitmap::from_trusted_len_iter(values)36}373839