Path: blob/main/crates/polars-arrow/src/bitmap/utils/chunks_exact_mut.rs
6939 views
use super::BitChunk;12/// An iterator over mutable slices of bytes of exact size.3///4/// # Safety5/// The slices returned by this iterator are guaranteed to have length equal to6/// `size_of::<T>()`.7#[derive(Debug)]8pub struct BitChunksExactMut<'a, T: BitChunk> {9chunks: std::slice::ChunksExactMut<'a, u8>,10remainder: &'a mut [u8],11remainder_len: usize,12marker: std::marker::PhantomData<T>,13}1415impl<'a, T: BitChunk> BitChunksExactMut<'a, T> {16/// Returns a new [`BitChunksExactMut`]17#[inline]18pub fn new(bitmap: &'a mut [u8], length: usize) -> Self {19assert!(length <= bitmap.len() * 8);20let size_of = size_of::<T>();2122let bitmap = &mut bitmap[..length.saturating_add(7) / 8];2324let split = (length / 8 / size_of) * size_of;25let (chunks, remainder) = bitmap.split_at_mut(split);26let remainder_len = length - chunks.len() * 8;2728let chunks = chunks.chunks_exact_mut(size_of);29Self {30chunks,31remainder,32remainder_len,33marker: std::marker::PhantomData,34}35}3637/// The remainder slice38#[inline]39pub fn remainder(&mut self) -> &mut [u8] {40self.remainder41}4243/// The length of the remainder slice in bits.44#[inline]45pub fn remainder_len(&mut self) -> usize {46self.remainder_len47}48}4950impl<'a, T: BitChunk> Iterator for BitChunksExactMut<'a, T> {51type Item = &'a mut [u8];5253#[inline]54fn next(&mut self) -> Option<Self::Item> {55self.chunks.next()56}5758#[inline]59fn size_hint(&self) -> (usize, Option<usize>) {60self.chunks.size_hint()61}62}636465