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§
- Create a list with provided elements.
Structs§
- A circular doubly linked list.
- A
Cursor
is like an iterator, except that it can freely seek back-and-forth. Thisstruct
is constructed by theCircularList::cursor
function. - Like a
Cursor
but with mutative operations on the list. Thisstruct
is constructed by theCircularList::cursor_mut
function. - A
DoubleCursor
is astruct
that points to 2 elements ‘a’ and ‘b’ of aCircularList
. One can thenswap
the 2 elements or put the first after the second etc. - An owning iterator over the elements of a
CircularList
. Thisstruct
is created byCircularList::into_iter()
.