Skip to main content

EntityRingList

Struct EntityRingList 

Source
pub struct EntityRingList<I: IEntityRingListNodeID> {
    pub sentinel: I,
}
Expand description

Ring list (circular) view over entities stored in an EntityAlloc.

The ring list is backed by a sentinel node that always exists; an empty ring has the sentinel’s next/prev pointing to itself. Nodes embed EntityListNodeHead for linkage and can be detached/attached at O(1).

Fields§

§sentinel: I

Sentinel node ID.

Implementations§

Source§

impl<I: IEntityRingListNodeID> EntityRingList<I>

Source

pub fn new(alloc: &IDBoundAlloc<I>) -> Self

Create a new empty ring list with a sentinel node.

Source

pub fn front_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>

Get the front node ID, or None if the list is empty. (Not sentinel)

Source

pub fn back_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>

Get the back node ID, or None if the list is empty. (Not sentinel)

Source

pub fn is_empty(&self, alloc: &IDBoundAlloc<I>) -> bool

Check if the ring list is empty.

Source

pub fn is_single(&self, alloc: &IDBoundAlloc<I>) -> bool

Check if the ring list has exactly one node (excluding sentinel).

Source

pub fn is_multiple(&self, alloc: &IDBoundAlloc<I>) -> bool

Check if the ring list has multiple nodes (excluding sentinel).

Source

pub fn foreach( &self, alloc: &IDBoundAlloc<I>, pred: impl FnMut(I, &I::ObjectT) -> bool, ) -> bool

traverse each node in the list, invoking pred on each node.

§panics

If a broken ring list is detected, this function will panic.

Source

pub fn forall_with_sentinel( &self, alloc: &IDBoundAlloc<I>, pred: impl FnMut(I, &I::ObjectT) -> bool, ) -> bool

traverse each node in the list starting from the sentinel, invoking pred on each node.

§panics

If a broken ring list is detected, this function will panic.

Source

pub fn len(&self, alloc: &IDBoundAlloc<I>) -> usize

Get the number of nodes in the ring list (excluding sentinel).

NOTE: This function traverses the entire list to count nodes, so its time complexity is O(n).

Source

pub fn contains(&self, node: I, alloc: &IDBoundAlloc<I>) -> bool

Check if the ring list contains the given node.

Source

pub fn clone_view(&self) -> Self

Create a clone of this ring list view (shares the same sentinel).

Source

pub fn push_back( &self, new_node: I, alloc: &IDBoundAlloc<I>, ) -> EntityListRes<I>

Push a new node to the back of the ring list.

Source

pub fn pop_back(&self, alloc: &IDBoundAlloc<I>) -> EntityListRes<I, I>

Pop a node from the back of the ring list.

Source

pub fn pop_front(&self, alloc: &IDBoundAlloc<I>) -> EntityListRes<I, I>

Pop a node from the front of the ring list.

Source

pub fn move_all_to( &self, other: &Self, alloc: &IDBoundAlloc<I>, on_move: impl FnMut(I), ) -> EntityListRes<I>

Move all nodes from self into other, preserving order; invoke on_move for each moved node.

Source

pub fn move_to_if( &self, other: &Self, alloc: &IDBoundAlloc<I>, pred: impl FnMut(I, &I::ObjectT) -> bool, on_move: impl FnMut(I), ) -> EntityListRes<I>

Move nodes that satisfy predicate from self to other, preserving order.

Source

pub fn clean(&self, alloc: &IDBoundAlloc<I>)

Clean up the ring list by removing all nodes; panic if a broken ring is detected.

Source

pub fn iter<'a>(&self, alloc: &'a IDBoundAlloc<I>) -> EntityRingListIter<'a, I>

Create an iterator over all nodes in the ring list (excluding sentinel).

Auto Trait Implementations§

§

impl<I> Freeze for EntityRingList<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for EntityRingList<I>
where I: RefUnwindSafe,

§

impl<I> Send for EntityRingList<I>
where I: Send,

§

impl<I> Sync for EntityRingList<I>
where I: Sync,

§

impl<I> Unpin for EntityRingList<I>
where I: Unpin,

§

impl<I> UnwindSafe for EntityRingList<I>
where I: UnwindSafe,

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.