pub struct CircularList<T> { /* private fields */ }
Expand description
A circular doubly linked list.
Implementations§
Source§impl<T> CircularList<T>
impl<T> CircularList<T>
Sourcepub fn add(&mut self, val: T)
pub fn add(&mut self, val: T)
Adds an element to the end of the list.
§Exemple
my_list.add("Hello");
assert_eq!(my_list.pop(), Some("Hello"))
Sourcepub fn remove(&mut self) -> Option<T>
pub fn remove(&mut self) -> Option<T>
Removes the first element of the list and returns it if any.
Sourcepub fn exchange(&mut self, i: usize, j: usize)
pub fn exchange(&mut self, i: usize, j: usize)
Exchanges the place of the element at position i
and the element at position j
.
This operation has O(n)
complexity. For a constant time swap operation, see
double_cursor
and DoubleCursor::swap
.
Sourcepub fn append(&mut self, other: Self)
pub fn append(&mut self, other: Self)
Assembles this list with another by putting all its elements at the end the list.
Sourcepub fn merge(&mut self, other: Self)where
T: PartialOrd,
pub fn merge(&mut self, other: Self)where
T: PartialOrd,
Assembles this list with another by keeping the elements sorted. It is assumed that the 2 lists are sorted.
Sourcepub fn sort(&mut self)where
T: PartialOrd,
pub fn sort(&mut self)where
T: PartialOrd,
Sorts the list.
Sourcepub fn left_rot(&mut self, count: usize)
pub fn left_rot(&mut self, count: usize)
Moves the head count
steps to the left.
§Example
let mut yoda_says: CircularList<_> = "ready you are not ".chars().collect();
yoda_says.left_rot(6);
assert_eq!("you are not ready ", yoda_says.into_iter().collect::<String>())
Sourcepub fn rotate(&mut self, count: isize)
pub fn rotate(&mut self, count: isize)
Rotate the head of the list count
times to the left if count > 0
or -count
times to
the right if count < 0
. Do nothing if count == 0
.
Sourcepub fn rotate_until<F: Fn(&T) -> bool>(&mut self, f: F)
pub fn rotate_until<F: Fn(&T) -> bool>(&mut self, f: F)
Rotate the head until the given condition is true. Do nothing on empty lists.
Sourcepub fn right_rot(&mut self, count: usize)
pub fn right_rot(&mut self, count: usize)
Moves the head count
steps to the right.
§Example
let mut yoda_says: CircularList<_> = "the greatest teacher failure is ".chars().collect();
yoda_says.right_rot(11);
assert_eq!("failure is the greatest teacher ", yoda_says.into_iter().collect::<String>())
Sourcepub fn iter_forever(&self) -> impl Iterator<Item = &T>
pub fn iter_forever(&self) -> impl Iterator<Item = &T>
Returns an infinite iterator over the list except if it is empty, in which case the returned iterator is also empty.
Sourcepub fn iter_mut_forever(&mut self) -> impl Iterator<Item = &mut T>
pub fn iter_mut_forever(&mut self) -> impl Iterator<Item = &mut T>
Returns an infinite iterator that allows modifying each value. The returned iterator is empty if the list is empty.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
Returns an iterator that allows modifying each value.
Sourcepub fn cursor(&self) -> Option<Cursor<'_, T>>
pub fn cursor(&self) -> Option<Cursor<'_, T>>
Returns some Cursor
pointing to the first element of the list (if any).
Sourcepub fn cursor_mut(&mut self) -> Option<CursorMut<'_, T>>
pub fn cursor_mut(&mut self) -> Option<CursorMut<'_, T>>
Returns some CursorMut
pointing to the first element of the list (if any).
Sourcepub fn double_cursor(&mut self) -> Option<DoubleCursor<'_, T>>
pub fn double_cursor(&mut self) -> Option<DoubleCursor<'_, T>>
Returns some DoubleCursor
where the ‘a’ and the ‘b’ parts are pointing both to the
first element of the list (if any).