Expand description
Circular doubly linked list.
The implementation is inspired by the linux implementation in C
.
§Basic usage
use cdll::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])§Safety considerations
This crate uses unsafe code to dereference raw pointers. In order for it to be sound, one
has to preserve some invariants (e.g. pointers must be valid). To achieve this, the source code
is commented with careful justifications to prove correctness (at least it is a try).
Macros§
- list
- Create a list with provided elements.
Structs§
- Circular
List - A circular doubly linked list.
- Cursor
- A
Cursoris like an iterator, except that it can freely seek back-and-forth. Thisstructis constructed by theCircularList::cursorfunction. - Cursor
Mut - Like a
Cursorbut with mutative operations on the list. Thisstructis constructed by theCircularList::cursor_mutfunction. - Double
Cursor - A
DoubleCursoris astructthat points to 2 elements ‘a’ and ‘b’ of aCircularList. One can thenswapthe 2 elements or put the first after the second etc. - Into
Iter - An owning iterator over the elements of a
CircularList. Thisstructis created byCircularList::into_iter().