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: ISentinel node ID.
Implementations§
Source§impl<I: IEntityRingListNodeID> EntityRingList<I>
impl<I: IEntityRingListNodeID> EntityRingList<I>
Sourcepub fn new(alloc: &IDBoundAlloc<I>) -> Self
pub fn new(alloc: &IDBoundAlloc<I>) -> Self
Create a new empty ring list with a sentinel node.
Sourcepub fn front_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
pub fn front_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
Get the front node ID, or None if the list is empty. (Not sentinel)
Sourcepub fn back_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
pub fn back_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
Get the back node ID, or None if the list is empty. (Not sentinel)
Sourcepub fn is_empty(&self, alloc: &IDBoundAlloc<I>) -> bool
pub fn is_empty(&self, alloc: &IDBoundAlloc<I>) -> bool
Check if the ring list is empty.
Sourcepub fn is_single(&self, alloc: &IDBoundAlloc<I>) -> bool
pub fn is_single(&self, alloc: &IDBoundAlloc<I>) -> bool
Check if the ring list has exactly one node (excluding sentinel).
Sourcepub fn is_multiple(&self, alloc: &IDBoundAlloc<I>) -> bool
pub fn is_multiple(&self, alloc: &IDBoundAlloc<I>) -> bool
Check if the ring list has multiple nodes (excluding sentinel).
Sourcepub fn foreach(
&self,
alloc: &IDBoundAlloc<I>,
pred: impl FnMut(I, &I::ObjectT) -> bool,
) -> bool
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.
Sourcepub fn forall_with_sentinel(
&self,
alloc: &IDBoundAlloc<I>,
pred: impl FnMut(I, &I::ObjectT) -> bool,
) -> bool
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.
Sourcepub fn len(&self, alloc: &IDBoundAlloc<I>) -> usize
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).
Sourcepub fn contains(&self, node: I, alloc: &IDBoundAlloc<I>) -> bool
pub fn contains(&self, node: I, alloc: &IDBoundAlloc<I>) -> bool
Check if the ring list contains the given node.
Sourcepub fn clone_view(&self) -> Self
pub fn clone_view(&self) -> Self
Create a clone of this ring list view (shares the same sentinel).
Sourcepub fn push_back(
&self,
new_node: I,
alloc: &IDBoundAlloc<I>,
) -> EntityListRes<I>
pub fn push_back( &self, new_node: I, alloc: &IDBoundAlloc<I>, ) -> EntityListRes<I>
Push a new node to the back of the ring list.
Sourcepub fn pop_back(&self, alloc: &IDBoundAlloc<I>) -> EntityListRes<I, I>
pub fn pop_back(&self, alloc: &IDBoundAlloc<I>) -> EntityListRes<I, I>
Pop a node from the back of the ring list.
Sourcepub fn pop_front(&self, alloc: &IDBoundAlloc<I>) -> EntityListRes<I, I>
pub fn pop_front(&self, alloc: &IDBoundAlloc<I>) -> EntityListRes<I, I>
Pop a node from the front of the ring list.
Sourcepub fn move_all_to(
&self,
other: &Self,
alloc: &IDBoundAlloc<I>,
on_move: impl FnMut(I),
) -> EntityListRes<I>
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.
Sourcepub fn move_to_if(
&self,
other: &Self,
alloc: &IDBoundAlloc<I>,
pred: impl FnMut(I, &I::ObjectT) -> bool,
on_move: impl FnMut(I),
) -> EntityListRes<I>
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.
Sourcepub fn clean(&self, alloc: &IDBoundAlloc<I>)
pub fn clean(&self, alloc: &IDBoundAlloc<I>)
Clean up the ring list by removing all nodes; panic if a broken ring is detected.
Sourcepub fn iter<'a>(&self, alloc: &'a IDBoundAlloc<I>) -> EntityRingListIter<'a, I> ⓘ
pub fn iter<'a>(&self, alloc: &'a IDBoundAlloc<I>) -> EntityRingListIter<'a, I> ⓘ
Create an iterator over all nodes in the ring list (excluding sentinel).