Struct CircularList

Source
pub struct CircularList<T> { /* private fields */ }
Expand description

A circular doubly linked list.

Implementations§

Source§

impl<T> CircularList<T>

Source

pub fn len(&self) -> usize

Gets the size of the list.

Source

pub fn is_empty(&self) -> bool

Returns true if the list contains no element.

Source

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"))
Source

pub fn peek(&self) -> &T

Returns a shared reference to the value of the list head.

§Panic

Panics if the list is empty.

Source

pub fn remove(&mut self) -> Option<T>

Removes the first element of the list and returns it if any.

Source

pub fn pop(&mut self) -> Option<T>

Removes the last element of the list and returns it if any.

Source

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.

Source

pub fn append(&mut self, other: Self)

Assembles this list with another by putting all its elements at the end the list.

Source

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.

Source

pub fn sort(&mut self)
where T: PartialOrd,

Sorts the list.

Source

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>())
Source

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.

Source

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.

Source

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>())
Source

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.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Returns an iterator over the list.

Source

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.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Returns an iterator that allows modifying each value.

Source

pub fn cursor(&self) -> Option<Cursor<'_, T>>

Returns some Cursor pointing to the first element of the list (if any).

Source

pub fn cursor_mut(&mut self) -> Option<CursorMut<'_, T>>

Returns some CursorMut pointing to the first element of the list (if any).

Source

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).

Trait Implementations§

Source§

impl<T: Clone> Clone for CircularList<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for CircularList<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for CircularList<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for CircularList<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> FromIterator<T> for CircularList<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> IntoIterator for CircularList<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CircularList<T>

§

impl<T> RefUnwindSafe for CircularList<T>
where T: RefUnwindSafe,

§

impl<T> !Send for CircularList<T>

§

impl<T> !Sync for CircularList<T>

§

impl<T> Unpin for CircularList<T>

§

impl<T> UnwindSafe for CircularList<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.