rusty_mos::utils::array_based_list

Struct ArrayLinkedList

Source
#[repr(C)]
pub struct ArrayLinkedList<const LEN: usize> { array: [ArrayLinkNode; LEN], head: Option<usize>, tail: Option<usize>, }
Expand description

The list itself. Maintain a head and tail and the node array.

§Generic

The const LEN means the node count. It should be specified at the compile time.

§Invariant

Both head and tail shall be None together or not be None together.

See Also: ArrayLinkNode

Fields§

§array: [ArrayLinkNode; LEN]

The array storing the linking field of each nodes.

§head: Option<usize>

The index of the first node. None means an empty node.

§tail: Option<usize>

The index of the last node. None means an empty node.

Implementations§

Source§

impl<const LEN: usize> ArrayLinkedList<LEN>

Source

pub const fn new() -> Self

Create a new link list and initialize the array.

Source

pub fn empty(&self) -> bool

Judge whether the list is empty.

Source

pub fn insert_head(&mut self, item: usize)

Insert the index item node into the head.

Source

pub fn peek_head(&self) -> Option<usize>

Peek the first node.

Source

pub fn pop_head(&mut self) -> Option<usize>

Get the first node. And remove it from the list if the list is not empty.

Source

pub fn insert_tail(&mut self, item: usize)

Insert the index item node into the tail.

Source

pub fn remove(&mut self, item: usize)

Remove the index item node from the list. This method requires that the node was in the list.

Source

pub fn contains(&self, item: usize) -> bool

Judge whether the node is in the list.

Trait Implementations§

Source§

impl<const LEN: usize> Default for ArrayLinkedList<LEN>

Source§

fn default() -> Self

Default constructions.

Auto Trait Implementations§

§

impl<const LEN: usize> Freeze for ArrayLinkedList<LEN>

§

impl<const LEN: usize> RefUnwindSafe for ArrayLinkedList<LEN>

§

impl<const LEN: usize> Send for ArrayLinkedList<LEN>

§

impl<const LEN: usize> Sync for ArrayLinkedList<LEN>

§

impl<const LEN: usize> Unpin for ArrayLinkedList<LEN>

§

impl<const LEN: usize> UnwindSafe for ArrayLinkedList<LEN>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.