pub struct UnrolledLinkedList<T> { /* private fields */ }
Expand description
The unrolled linked list. The list that acts like a linked list but has the node structure inside.
Implementations§
Source§impl<'a, T> UnrolledLinkedList<T>
impl<'a, T> UnrolledLinkedList<T>
Sourcepub fn iter(&self) -> Iter<'a, T> ⓘ
pub fn iter(&self) -> Iter<'a, T> ⓘ
Provides a forward iterator.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let mut list: UnrolledLinkedList<u32> = UnrolledLinkedList::new();
list.push(0);
list.push(1);
list.push(2);
let mut iter = list.iter();
assert_eq!(iter.next(), Some(&0));
assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), None);
Sourcepub fn iter_mut(&'a mut self) -> IterMut<'a, T> ⓘ
pub fn iter_mut(&'a mut self) -> IterMut<'a, T> ⓘ
Provides a forward mut iterator.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let mut list: UnrolledLinkedList<u32> = UnrolledLinkedList::new();
list.push(0);
list.push(1);
list.push(2);
for element in list.iter_mut() {
*element += 10;
}
let mut iter = list.iter();
assert_eq!(iter.next(), Some(&10));
assert_eq!(iter.next(), Some(&11));
assert_eq!(iter.next(), Some(&12));
assert_eq!(iter.next(), None);
Source§impl<T> UnrolledLinkedList<T>
impl<T> UnrolledLinkedList<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
The default initiation, setting the size of node to 8.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let list: UnrolledLinkedList<u32> = UnrolledLinkedList::new();
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Capacity defines the size of the node.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let list: UnrolledLinkedList<u32> = UnrolledLinkedList::with_capacity(4);
Source§impl<T> UnrolledLinkedList<T>
impl<T> UnrolledLinkedList<T>
Sourcepub fn push(&mut self, el: T)
pub fn push(&mut self, el: T)
Adds an element last in the list.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let mut dl = UnrolledLinkedList::new();
dl.push(2);
assert_eq!(dl.pop().unwrap(), 2);
dl.push(1);
assert_eq!(dl.pop().unwrap(), 1);
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
removes the last element from the list and returns it.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let mut dl = UnrolledLinkedList::new();
dl.insert(0,0);
assert_eq!(dl.pop().unwrap(), 0);
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
retrieves the custom element from the list according to the index and returns it.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let mut dl = UnrolledLinkedList::new();
dl.insert(0,0);
dl.insert(1,1);
assert_eq!(dl.get(1), Some(&1));
assert_eq!(dl.get(0), Some(&0));
Sourcepub fn get_mut(&self, index: usize) -> Option<&mut T>
pub fn get_mut(&self, index: usize) -> Option<&mut T>
retrieves the custom element from the list according to the index and returns the mutable reference.
§Examples
use unrolled_linked_list::UnrolledLinkedList;
let mut dl = UnrolledLinkedList::new();
dl.insert(0,0);
dl.insert(1,1);
assert_eq!(dl.get_mut(1), Some(&mut 1));
assert_eq!(dl.get_mut(0), Some(&mut 0));
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the UnrolledLinkedList
is empty.
This operation should compute in O(1) time.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the UnrolledLinkedList
.
This operation should compute in O(1) time.
Trait Implementations§
Source§impl<T: Debug> Debug for UnrolledLinkedList<T>
impl<T: Debug> Debug for UnrolledLinkedList<T>
Source§impl<T> Default for UnrolledLinkedList<T>
impl<T> Default for UnrolledLinkedList<T>
Source§impl<T> Display for UnrolledLinkedList<T>
impl<T> Display for UnrolledLinkedList<T>
Source§impl<'a, T> IntoIterator for &'a UnrolledLinkedList<T>
impl<'a, T> IntoIterator for &'a UnrolledLinkedList<T>
Auto Trait Implementations§
impl<T> Freeze for UnrolledLinkedList<T>
impl<T> RefUnwindSafe for UnrolledLinkedList<T>where
T: RefUnwindSafe,
impl<T> !Send for UnrolledLinkedList<T>
impl<T> !Sync for UnrolledLinkedList<T>
impl<T> Unpin for UnrolledLinkedList<T>
impl<T> UnwindSafe for UnrolledLinkedList<T>where
T: RefUnwindSafe,
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