Crates.io | cdll |
lib.rs | cdll |
version | 0.4.2 |
source | src |
created_at | 2022-03-15 21:59:39.587786 |
updated_at | 2024-05-13 21:06:01.978068 |
description | A circular doubly linked list |
homepage | |
repository | https://github.com/devalain/cll |
max_upload_size | |
id | 550729 |
size | 75,723 |
Inspired from the linux kernel list.
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]);
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]
);