Skip to main content

DLinkedList

Struct DLinkedList 

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

An intrusive doubly linked list.

Supports O(1) insertion and removal at both ends.

Implementations§

Source§

impl<P, Tag> DLinkedList<P, Tag>
where P: Pointer, P::Target: DListItem<Tag>,

Source

pub fn new() -> Self

Creates a new, empty doubly 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 unsafe fn peak(&mut self, ptr: *mut P::Target)

Moves a node to the front of the list (e.g., for LRU updates).

§Safety

The pointer ptr must be valid and pointing to an element currently in the list or a valid free element if properly managed (though typically used for re-ordering).

Source

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

Pushes an element to the front of the list.

Source

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

Pushes an element to the back of the list.

Source

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

Removes and returns the element at the front of the list.

Source

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

Removes and returns the element at the back of the list.

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 print<U: Debug>(&self)

Available on crate feature std only.
Source

pub fn iter<'a>(&'a self) -> DLinkedListIterator<'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) -> DLinkedListDrainer<'a, P, Tag>

Returns a draining iterator that removes items from the list. Crucial for cleaning up lists containing owned pointers (like Box).

§Note

The iterator removes elements from the front of the list (FIFO order),

Trait Implementations§

Source§

impl<P, Tag> Debug for DLinkedList<P, Tag>
where P: Pointer + Debug, P::Target: DListItem<Tag>,

Source§

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

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

impl<P, Tag> Drop for DLinkedList<P, Tag>
where P: Pointer, P::Target: DListItem<Tag>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<P, Tag> Send for DLinkedList<P, Tag>
where P: Pointer, P::Target: DListItem<Tag>,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<P, Tag> UnwindSafe for DLinkedList<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.