scanline-core 0.1.0-alpha.0

Scanline execution engine — chunk scheduling, core-affinity pinning, and the query execution loop.
Documentation
//! Scanline execution engine.
//!
//! Owns the query execution loop: it takes an aligned buffer from
//! `scanline-storage`, splits it into per-core chunks, and drives the predicate
//! kernels in `scanline-simd` across pinned worker threads.
//!
//! Phase 0 scaffold: the chunk scheduler and core-affinity pinning land in
//! Phase 1. What exists here now is the single-threaded execution path, which is
//! already enough to saturate a meaningful fraction of memory bandwidth and is
//! the baseline every parallel result must beat.

use scanline_simd::Backend;
use scanline_storage::AlignedVec;

/// Outcome of one scan, carrying enough context to be reported honestly.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScanResult {
    /// Rows satisfying the predicate.
    pub matches: usize,
    /// Rows examined.
    pub rows: usize,
    /// Backend that actually executed.
    pub backend: Backend,
}

impl ScanResult {
    /// Bytes read from memory by this scan, assuming a dense `i64` column.
    #[must_use]
    pub const fn bytes_read(&self) -> usize {
        self.rows * std::mem::size_of::<i64>()
    }
}

/// Runs a greater-than predicate over an aligned `i64` buffer.
#[must_use]
pub fn scan_greater_than(data: &AlignedVec<i64>, target: i64) -> ScanResult {
    let backend = scanline_simd::detect_backend();
    ScanResult {
        matches: scanline_simd::scan_greater_than_i64_with(data, target, backend),
        rows: data.len(),
        backend,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn scan_over_aligned_buffer_counts_correctly() {
        let mut buf = AlignedVec::<i64>::zeroed_cache_aligned(1000);
        for (i, slot) in buf.iter_mut().enumerate() {
            *slot = i as i64;
        }

        let result = scan_greater_than(&buf, 499);

        assert_eq!(result.matches, 500);
        assert_eq!(result.rows, 1000);
        assert_eq!(result.bytes_read(), 8000);
    }

    #[test]
    fn scan_over_empty_buffer_is_zero() {
        let buf = AlignedVec::<i64>::zeroed_cache_aligned(0);
        let result = scan_greater_than(&buf, 0);
        assert_eq!(result.matches, 0);
        assert_eq!(result.rows, 0);
    }
}