Struct UnrolledLinkedList

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

Source

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

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>

Source

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

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>

Source

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

pub fn insert(&mut self, index: usize, el: T)

Adds an element last in the list.

§Panics

Panics if index > len.

§Examples

use unrolled_linked_list::UnrolledLinkedList;
let mut dl = UnrolledLinkedList::new();

dl.insert(0,0);
assert_eq!(dl.pop().unwrap(), 0);
Source

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

pub fn remove(&mut self, index: usize) -> T

removes the custom element from the list accordign to the index and returns it.

§Panics

Panics if index >= len.

§Examples

use unrolled_linked_list::UnrolledLinkedList;
let mut dl = UnrolledLinkedList::new();

dl.insert(0,0);
assert_eq!(dl.remove(0), 0);
Source

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

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

pub fn is_empty(&self) -> bool

Returns true if the UnrolledLinkedList is empty.

This operation should compute in O(1) time.

Source

pub fn len(&self) -> usize

Returns the length of the UnrolledLinkedList.

This operation should compute in O(1) time.

Source

pub fn clear(&mut self)

Removes all elements from the LinkedList.

This operation should compute in O(n) time.

Source

pub fn contains(&self, x: &T) -> bool
where T: PartialEq<T>,

Returns true if the LinkedList contains an element equal to the given value.

Trait Implementations§

Source§

impl<T: Debug> Debug for UnrolledLinkedList<T>

Source§

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

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

impl<T> Default for UnrolledLinkedList<T>

Source§

fn default() -> Self

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

impl<T> Display for UnrolledLinkedList<T>

Source§

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

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

impl<'a, T> IntoIterator for &'a UnrolledLinkedList<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, 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
Source§

impl<T> IntoIterator for UnrolledLinkedList<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§

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.