DoublyLinkedList

Struct DoublyLinkedList 

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

Vec based doubly linked list implementation

§Example

use lru_st::DoublyLinkedList;

let mut dll = DoublyLinkedList::new();
dll.push_front(42);
dll.push_front(43);

assert_eq!(dll.back(), Some(&42));
assert_eq!(dll.front(), Some(&43));

dll.push_back(44);
assert_eq!(dll.front(), Some(&43));
assert_eq!(dll.back(), Some(&44));

Implementations§

Source§

impl<T> DoublyLinkedList<T>

Source

pub fn new() -> Self

Creates a new empty DoublyLinkedList

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new empty DoublyLinkedList with a given capacity

Source

pub fn from_vec(v: Vec<T>) -> Self

Creates a new DoublyLinkedList from a Vec

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty

Source

pub fn push_front(&mut self, v: T) -> Cursor

Pushes an element to the front of the list

Source

pub fn push_back(&mut self, v: T) -> Cursor

Pushes an element to the back of the list and returning the Cursor pointing to this element. The Cursor can then be used to directly access/move/pop element.

Source

pub fn get(&self, c: Cursor) -> Option<&T>

Get the element in the list at a given Cursor or None if there is no element. If wanting to get an element at a given position see DoublyLinkedList::get_nth.

Source

pub fn get_nth(&self, n: usize) -> Option<&T>

Get an element given its position in the list

Source

pub fn get_mut(&mut self, c: Cursor) -> Option<&mut T>

Get a mutable element at a given position in the list or None if there is no element.

Source

pub fn get_mut_nth(&mut self, n: usize) -> Option<&mut T>

Get an element given its position in the list

Source

pub fn front(&self) -> Option<&T>

Get the element at the front of the list

Source

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

Get a mutable reference to the element at the front of the list

Source

pub fn back(&self) -> Option<&T>

Get the element a the back of the list

Source

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

Get a mutable reference to the element at the back of the list

Source

pub fn len(&self) -> usize

Returns the number of elements in the list

Source

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

Pops the element a the back of the list

Source

pub fn iter(&self) -> DoublyLinkedListIter<'_, T>

Provides an iterator (i.e. DoublyLinkedListIter) over the elements of the list

Source

pub fn move_front(&mut self, at: Cursor) -> Result<(), Error>

Move item at cursor to the head of list

Source

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

Pops the item at front of the doubly linked list

Source

pub fn pop(&mut self, at: Cursor) -> Option<T>

Pops the item located at at Cursor in the doubly linked list. This API pops an element according to its Cursor which is not corresponding to its position within the linked list. To pop an item according to its position in the linked list use pop_nth.

Source

pub fn pop_nth(&mut self, n: usize) -> Option<T>

Pops the nth element of linked list

Trait Implementations§

Source§

impl<T> Debug for DoublyLinkedList<T>
where T: Debug,

Source§

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

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

impl<T> Default for DoublyLinkedList<T>

Source§

fn default() -> Self

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

impl<T> Display for DoublyLinkedList<T>
where T: Display,

Source§

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

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

impl<T> PartialEq for DoublyLinkedList<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for DoublyLinkedList<T>

§

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

§

impl<T> Send for DoublyLinkedList<T>
where T: Send,

§

impl<T> Sync for DoublyLinkedList<T>
where T: Sync,

§

impl<T> Unpin for DoublyLinkedList<T>
where T: Unpin,

§

impl<T> UnwindSafe for DoublyLinkedList<T>
where T: UnwindSafe,

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.