frodo-ring 0.1.0

Ring queue with FIFO ordering with no allocations
Documentation
  • Coverage
  • 100%
    15 out of 15 items documented0 out of 14 items with examples
  • Size
  • Source code size: 29.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.76 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • markcda

frodo-ring

Предоставляет реализацию очереди FIFO на кольцевом буфере, не использующем аллокации.

Пример:

fn main() -> Result<(), u8> {
    let mut ring = FrodoRing::<u8, 4>::new();

    ring.push(0x1)?;
    ring.push(0x2)?;
    ring.push(0x3)?;
    ring.push(0x4)?;

    println!("Первая ячейка: {}", ring.at(0).unwrap());
    println!("Последняя ячейка: {}", ring.at(-1).unwrap());

    ring.remove_at(1);

    assert_eq!(ring.at(0), Some(&0x1));
    assert_eq!(ring.at(1), None);
    assert_eq!(ring.at(2), Some(&0x3));
    assert_eq!(ring.at(3), ring.at(-1));

    assert_eq!(ring.get(0), Some(&0x1));
    assert_eq!(ring.get(1), Some(&0x3));
    assert_eq!(ring.get(2), Some(&0x4));

    let pos = ring.position(|el| *el == 0x3).unwrap();
    assert_eq!(ring.remove_at(pos), Some(0x3));

    println!("Элементы:");
    for el in ring.iter() {
        println!("\t{el}");
    }

    assert_eq!(ring.used(), 4);
    assert_eq!(ring.len(), 2);

    assert_eq!(ring.pick(), Some(0x1));

    assert_eq!(ring.used(), 1);
    assert_eq!(ring.len(), 1);

    Ok(())
}