sliding-ring 0.1.1

Cache-friendly sliding ring buffer keyed to an anchor coordinate for ultra-low-latency workloads.
Documentation
use sliding_ring::{Direction, SlidingRing};
use wide::u64x4;

fn contains_with_wide(slice: &[u64], needle: u64) -> bool {
    let needle_vec = u64x4::splat(needle);
    let mut chunks = slice.chunks_exact(4);
    for chunk in chunks.by_ref() {
        let vec = u64x4::new([chunk[0], chunk[1], chunk[2], chunk[3]]);
        // `simd_eq` returns either all-ones or zeros per lane; check if any lane matched.
        if vec
            .simd_eq(needle_vec)
            .to_array()
            .iter()
            .any(|&lane| lane == u64::MAX)
        {
            return true;
        }
    }
    chunks.remainder().iter().any(|&value| value == needle)
}

fn main() {
    const DEPTH: u8 = 64;
    let mut ring = SlidingRing::<u64, DEPTH>::new(0);
    for i in 0..DEPTH {
        *ring.slot_mut(i) = i as u64;
    }

    let (tail, head) = ring.slices_from_anchor();
    if contains_with_wide(tail, 42) {
        println!("found 42 in anchor tail slice");
    } else if contains_with_wide(head, 42) {
        println!("found 42 in wraparound slice");
    } else {
        println!("42 not present; falling back to scalar iteration");
    }

    let total: u64 = ring
        .iter_from_anchor(Direction::Forward)
        .take(5)
        .map(|(_, slot)| *slot)
        .sum();
    println!("first 5 totals: {}", total);
}