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

Method zip_modify

arrow-buffer/src/util/bit_util.rs:551–585  ·  view source on GitHub ↗

Modify the underlying u64 data in place using a binary operation with another iterator.

(
        mut self,
        mut zip_iter: impl ExactSizeIterator<Item = u64>,
        mut map: impl FnMut(u64, u64) -> u64,
    )

Source from the content-addressed store, hash-verified

549 /// Modify the underlying u64 data in place using a binary operation
550 /// with another iterator.
551 fn zip_modify(
552 mut self,
553 mut zip_iter: impl ExactSizeIterator<Item = u64>,
554 mut map: impl FnMut(u64, u64) -> u64,
555 ) {
556 assert_eq!(self.len, zip_iter.len());
557
558 // In order to avoid advancing the pointer at the end of the loop which will
559 // make the last pointer invalid, we handle the first element outside the loop
560 // and then advance the pointer at the start of the loop
561 // making sure that the iterator is not empty
562 if let Some(right) = zip_iter.next() {
563 // SAFETY: We asserted that the iterator length and the current length are the same
564 // and the iterator is not empty, so the pointer is valid
565 unsafe {
566 self.apply_bin_op(right, &mut map);
567 }
568
569 // Because this consumes self we don't update the length
570 }
571
572 for right in zip_iter {
573 // Advance the pointer
574 //
575 // SAFETY: We asserted that the iterator length and the current length are the same
576 self.ptr = unsafe { self.ptr.add(1) };
577
578 // SAFETY: the pointer is valid as we are within the length
579 unsafe {
580 self.apply_bin_op(right, &mut map);
581 }
582
583 // Because this consumes self we don't update the length
584 }
585 }
586
587 /// Centralized function to correctly read the current u64 value and write back the result
588 ///

Callers 1

Calls 3

apply_bin_opMethod · 0.80
nextMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected