use scanline_simd::Backend;
use scanline_storage::AlignedVec;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScanResult {
pub matches: usize,
pub rows: usize,
pub backend: Backend,
}
impl ScanResult {
#[must_use]
pub const fn bytes_read(&self) -> usize {
self.rows * std::mem::size_of::<i64>()
}
}
#[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);
}
}