cdll

Crates.iocdll
lib.rscdll
version0.4.2
sourcesrc
created_at2022-03-15 21:59:39.587786
updated_at2024-05-13 21:06:01.978068
descriptionA circular doubly linked list
homepage
repositoryhttps://github.com/devalain/cll
max_upload_size
id550729
size75,723
(devalain)

documentation

README

Circular Linked List written in rust

crate docs

Inspired from the linux kernel list.

Basic usage

use cll::CircularList;

let mut my_list = CircularList::default();
for x in 1..=5 {
    my_list.add(x);
}

assert_eq!(my_list.remove(), Some(1));
assert_eq!(my_list.pop(), Some(5));

my_list.iter_mut().for_each(|x: &mut i32| *x -= 1);
assert_eq!(my_list.into_iter().collect::<Vec<i32>>(), &[1, 2, 3]);

Example of sorting using double_cursor

use cll::list;

let mut list = list![3, 1, 8, 21, 5, 9, 12, 5, 2, 6, 6, 6, 13, 2, 17];
let len = list.len();
let mut dc = list
    .double_cursor()
    .expect("A cursor should always be available on a non empty list");

let mut min = *dc.value_a();
for i in 1..len {
    dc.set_b_to_a();
    dc.push_a();
    for _ in i..len {
        dc.move_next_a();
        let val = *dc.value_a();
        if val < min {
            min = val;
            dc.set_b_to_a();
        }
    }
    dc.pop_a();
    dc.insert_b_before_a();
    if dc.a_is_b() {
        dc.move_next_a();
    }
    min = *dc.value_a();
}
assert_eq!(
    list.into_iter().collect::<Vec<i32>>(),
    &[1, 2, 2, 3, 5, 5, 6, 6, 6, 8, 9, 12, 13, 17, 21]
);
Commit count: 53

cargo fmt