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>
impl<T> DoublyLinkedList<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty DoublyLinkedList
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new empty DoublyLinkedList with a given capacity
Sourcepub fn from_vec(v: Vec<T>) -> Self
pub fn from_vec(v: Vec<T>) -> Self
Creates a new DoublyLinkedList from a Vec
Sourcepub fn push_front(&mut self, v: T) -> Cursor
pub fn push_front(&mut self, v: T) -> Cursor
Pushes an element to the front of the list
Sourcepub fn get(&self, c: Cursor) -> Option<&T>
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.
Sourcepub fn get_mut(&mut self, c: Cursor) -> Option<&mut T>
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.
Sourcepub fn get_mut_nth(&mut self, n: usize) -> Option<&mut T>
pub fn get_mut_nth(&mut self, n: usize) -> Option<&mut T>
Get an element given its position in the list
Sourcepub fn front_mut(&mut self) -> Option<&mut T>
pub fn front_mut(&mut self) -> Option<&mut T>
Get a mutable reference to the element at the front of the list
Sourcepub fn back_mut(&mut self) -> Option<&mut T>
pub fn back_mut(&mut self) -> Option<&mut T>
Get a mutable reference to the element at the back of the list
Sourcepub fn iter(&self) -> DoublyLinkedListIter<'_, T> ⓘ
pub fn iter(&self) -> DoublyLinkedListIter<'_, T> ⓘ
Provides an iterator (i.e. DoublyLinkedListIter) over the elements of the list
Sourcepub fn move_front(&mut self, at: Cursor) -> Result<(), Error>
pub fn move_front(&mut self, at: Cursor) -> Result<(), Error>
Move item at cursor to the head of list
Trait Implementations§
Source§impl<T> Debug for DoublyLinkedList<T>where
T: Debug,
impl<T> Debug for DoublyLinkedList<T>where
T: Debug,
Source§impl<T> Default for DoublyLinkedList<T>
impl<T> Default for DoublyLinkedList<T>
Source§impl<T> Display for DoublyLinkedList<T>where
T: Display,
impl<T> Display for DoublyLinkedList<T>where
T: Display,
Source§impl<T> PartialEq for DoublyLinkedList<T>where
T: PartialEq,
impl<T> PartialEq for DoublyLinkedList<T>where
T: PartialEq,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more