shift_int

Function shift_int 

Source
pub fn shift_int<T: Copy + Default>(
    window: IntegerAVT<'_, T>,
    offset: isize,
) -> IntegerArray<T>
Expand description

Shifts integer array elements by specified offset with bidirectional support.

Provides unified interface for both LAG and LEAD operations through signed offset parameter. Positive offsets implement LEAD semantics (forward shift), negative offsets implement LAG semantics (backward shift), enabling flexible positional access.

§Parameters

  • window - Integer array view containing data for shifting
  • offset - Signed offset: positive for LEAD (forward), negative for LAG (backward), zero for identity

§Returns

Returns an IntegerArray<T> containing:

  • Shifted integer values according to offset direction
  • Default values for positions beyond available data
  • Null mask reflecting validity of shifted positions

§Shift Semantics

  • Positive offset: LEAD operation (shift left, access future values)
  • Negative offset: LAG operation (shift right, access past values)
  • Zero offset: Identity operation (returns original array)
  • Boundary handling: Out-of-bounds positions receive default values

§Applications

  • Time series analysis: Flexible temporal shifting for comparison operations
  • Sequence processing: Bidirectional access in ordered integer sequences
  • Algorithm implementation: Building blocks for complex windowing operations
  • Data transformation: Positional transformations in numerical datasets

§Examples

use minarrow::IntegerArray;
use simd_kernels::kernels::window::shift_int;

let arr = IntegerArray::<i32>::from_slice(&[1, 2, 3, 4]);
let lag = shift_int((&arr, 0, arr.len()), -1);  // LAG by 1
let lead = shift_int((&arr, 0, arr.len()), 2);  // LEAD by 2
// lag:  [0, 1, 2, 3] - previous values
// lead: [3, 4, 0, 0] - future values