MCPcopy Create free account
hub / github.com/apache/arrow-rs / bit_slice

Method bit_slice

arrow-buffer/src/buffer/immutable.rs:330–346  ·  view source on GitHub ↗

Returns a slice of this buffer starting at a certain bit offset. If the offset is byte-aligned the returned buffer is a shallow clone, otherwise a new buffer is allocated and filled with a copy of the bits in the range.

(&self, offset: usize, len: usize)

Source from the content-addressed store, hash-verified

328 /// If the offset is byte-aligned the returned buffer is a shallow clone,
329 /// otherwise a new buffer is allocated and filled with a copy of the bits in the range.
330 pub fn bit_slice(&self, offset: usize, len: usize) -> Self {
331 if offset % 8 == 0 {
332 return self.slice_with_length(offset / 8, bit_util::ceil(len, 8));
333 }
334
335 let chunks = self.bit_chunks(offset, len);
336
337 let buffer: Vec<u64> = if chunks.remainder_len() > 0 {
338 chunks.iter().chain(Some(chunks.remainder_bits())).collect()
339 } else {
340 chunks.iter().collect()
341 };
342 let mut buffer = Buffer::from_vec(buffer);
343 // Update length to be byte-aligned
344 buffer.length = bit_util::ceil(len, 8);
345 buffer
346 }
347
348 /// Returns a `BitChunks` instance which can be used to iterate over this buffers bits
349 /// in larger chunks and starting at arbitrary bit offsets.

Callers 3

slicedMethod · 0.80
write_array_dataFunction · 0.80

Calls 7

slice_with_lengthMethod · 0.80
remainder_lenMethod · 0.80
collectMethod · 0.80
remainder_bitsMethod · 0.80
ceilFunction · 0.50
bit_chunksMethod · 0.45
iterMethod · 0.45

Tested by 1