Skip to main content

SLinkedList

Struct SLinkedList 

Source
pub struct SLinkedList<P, Tag>
where P: Pointer, P::Target: SListItem<Tag>,
{ /* private fields */ }
Available on crate feature slist only.
Expand description

A singly linked list with head and tail pointers (FIFO queue).

Supports O(1) push to back and pop from front.

Implementations§

Source§

impl<P, Tag> SLinkedList<P, Tag>
where P: Pointer, P::Target: SListItem<Tag>,

Source

pub fn new() -> Self

Creates a new, empty singly linked list.

Source

pub fn clear(&mut self)

Clears the list pointers. Note: This does NOT drop the elements. Use drain or drop if you need to release owned resources.

Source

pub fn get_length(&self) -> u64

Returns the length of the list.

Source

pub fn len(&self) -> usize

Returns the length of the list as usize.

Source

pub fn is_empty(&self) -> bool

Returns true if the list contains no elements.

Source

pub fn push_back(&mut self, item: P)

Appends an element to the back of the list (FIFO: enqueue).

Source

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

Removes the first element and returns it (FIFO: dequeue).

Source

pub fn get_front(&self) -> Option<&P::Target>

Returns a reference to the front element.

Source

pub fn get_back(&self) -> Option<&P::Target>

Returns a reference to the back element.

Source

pub fn is_front(&self, node: &P::Target) -> bool

Checks if the given node is the head of the list.

Source

pub fn iter<'a>(&'a self) -> SLinkedListIterator<'a, P, Tag>

Returns an iterator over the list (borrowed).

§NOTE

If you plan on turn the raw pointer to owned, use drain instead

§Safety

The caller must ensure that the list is not modified in a way that can invalidate internal pointers (such as removing elements or dropping items) for the duration of the iterator’s use.

Source

pub fn drain<'a>(&'a mut self) -> SLinkedListDrainer<'a, P, Tag>

Returns a draining iterator that removes items from the list.

Trait Implementations§

Source§

impl<P, Tag> Debug for SLinkedList<P, Tag>
where P: Pointer + Debug, P::Target: SListItem<Tag>,

Source§

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

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

impl<P, Tag> Drop for SLinkedList<P, Tag>
where P: Pointer, P::Target: SListItem<Tag>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<P, Tag> Send for SLinkedList<P, Tag>
where P: Pointer, P::Target: SListItem<Tag>,

Auto Trait Implementations§

§

impl<P, Tag> Freeze for SLinkedList<P, Tag>
where <P as Pointer>::Target: Sized,

§

impl<P, Tag> RefUnwindSafe for SLinkedList<P, Tag>
where <P as Pointer>::Target: Sized + RefUnwindSafe,

§

impl<P, Tag> !Sync for SLinkedList<P, Tag>

§

impl<P, Tag> Unpin for SLinkedList<P, Tag>
where <P as Pointer>::Target: Sized,

§

impl<P, Tag> UnwindSafe for SLinkedList<P, Tag>
where <P as Pointer>::Target: Sized + RefUnwindSafe,

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, 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.