1use scanline_simd::Backend;
13use scanline_storage::AlignedVec;
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct ScanResult {
18 pub matches: usize,
20 pub rows: usize,
22 pub backend: Backend,
24}
25
26impl ScanResult {
27 #[must_use]
29 pub const fn bytes_read(&self) -> usize {
30 self.rows * std::mem::size_of::<i64>()
31 }
32}
33
34#[must_use]
36pub fn scan_greater_than(data: &AlignedVec<i64>, target: i64) -> ScanResult {
37 let backend = scanline_simd::detect_backend();
38 ScanResult {
39 matches: scanline_simd::scan_greater_than_i64_with(data, target, backend),
40 rows: data.len(),
41 backend,
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn scan_over_aligned_buffer_counts_correctly() {
51 let mut buf = AlignedVec::<i64>::zeroed_cache_aligned(1000);
52 for (i, slot) in buf.iter_mut().enumerate() {
53 *slot = i as i64;
54 }
55
56 let result = scan_greater_than(&buf, 499);
57
58 assert_eq!(result.matches, 500);
59 assert_eq!(result.rows, 1000);
60 assert_eq!(result.bytes_read(), 8000);
61 }
62
63 #[test]
64 fn scan_over_empty_buffer_is_zero() {
65 let buf = AlignedVec::<i64>::zeroed_cache_aligned(0);
66 let result = scan_greater_than(&buf, 0);
67 assert_eq!(result.matches, 0);
68 assert_eq!(result.rows, 0);
69 }
70}