pub struct EntityList<I: IEntityListNodeID> {
pub head: I,
pub tail: I,
pub len: Cell<usize>,
}Expand description
Doubly-linked list view over entities stored in an EntityAlloc.
Logical structure: the list uses head/tail sentinel nodes (allocated via
the entity allocator) and maintains EntityListNodeHead inside each
entity to chain nodes. Physical structure: no extra heap nodes are
allocated—linkage is stored inline within entity storage.
The list invokes signals (on_push_*, on_unplug) on nodes before
modifying links; these signals may veto operations by returning an error.
Many operations assume the node is not already attached to another list;
violating that assumption may lead to an inconsistent list (reported as
ListBroken).
Fields§
§head: IHead sentinel node ID.
tail: ITail sentinel node ID.
len: Cell<usize>Number of nodes in the list (excluding sentinels).
Implementations§
Source§impl<I: IEntityListNodeID> EntityList<I>
impl<I: IEntityListNodeID> EntityList<I>
Sourcepub fn new(alloc: &IDBoundAlloc<I>) -> Self
pub fn new(alloc: &IDBoundAlloc<I>) -> Self
create a new empty list with head and tail sentinels linked with each other.
Sourcepub fn get_front_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
pub fn get_front_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
try to get the front node ID, or None if the list is empty
Sourcepub fn get_back_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
pub fn get_back_id(&self, alloc: &IDBoundAlloc<I>) -> Option<I>
try to get the back node ID, or None if the list is empty
Sourcepub fn node_add_next(
&self,
node: I,
new_node: I,
alloc: &IDBoundAlloc<I>,
) -> EntityListRes<I>
pub fn node_add_next( &self, node: I, new_node: I, alloc: &IDBoundAlloc<I>, ) -> EntityListRes<I>
Add a new node after an existing node linked to this list.
If the current node is linked to another list, then the operation is undefined. You’ll get a broken list without reporting an error.
§Signal invocation
node_add_next will invoke on_push_next on node before modifying any links.
If the signal returns an error, the operation is aborted without modifying any links.
Sourcepub fn node_add_prev(
&self,
node: I,
new_node: I,
alloc: &IDBoundAlloc<I>,
) -> EntityListRes<I>
pub fn node_add_prev( &self, node: I, new_node: I, alloc: &IDBoundAlloc<I>, ) -> EntityListRes<I>
Add a new node before an existing node linked to this list.
If the current node is linked to another list, then the operation is undefined. You’ll get a broken list without reporting an error.
§Signal invocation
node_add_prev will invoke on_push_prev on node before modifying any links.
If the signal returns an error, the operation is aborted without modifying any links.
Sourcepub fn node_unplug(&self, node: I, alloc: &IDBoundAlloc<I>) -> EntityListRes<I>
pub fn node_unplug(&self, node: I, alloc: &IDBoundAlloc<I>) -> EntityListRes<I>
Unplug a node from the list.
§Signal invocation
node_unplug will invoke on_unplug on node before modifying any links.
If the signal returns an error, the operation is aborted without modifying any links.
Sourcepub fn push_back_id(
&self,
new_node: I,
alloc: &IDBoundAlloc<I>,
) -> EntityListRes<I>
pub fn push_back_id( &self, new_node: I, alloc: &IDBoundAlloc<I>, ) -> EntityListRes<I>
Push a new node to the back of the list.
Sourcepub fn push_front_id(
&self,
new_node: I,
alloc: &IDBoundAlloc<I>,
) -> EntityListRes<I>
pub fn push_front_id( &self, new_node: I, alloc: &IDBoundAlloc<I>, ) -> EntityListRes<I>
Push a new node to the front of the 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 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 list.
Sourcepub fn get_range(&self, alloc: &IDBoundAlloc<I>) -> EntityListRange<I>
pub fn get_range(&self, alloc: &IDBoundAlloc<I>) -> EntityListRange<I>
Get a range covering all nodes in the list (excluding sentinels).
Sourcepub fn get_range_with_sentinels(&self) -> EntityListRange<I>
pub fn get_range_with_sentinels(&self) -> EntityListRange<I>
Get a range covering all nodes in the list (including sentinels).
Sourcepub fn iter<'alloc>(
&self,
alloc: &'alloc IDBoundAlloc<I>,
) -> EntityListIter<'alloc, I> ⓘ
pub fn iter<'alloc>( &self, alloc: &'alloc IDBoundAlloc<I>, ) -> EntityListIter<'alloc, I> ⓘ
Create an iterator over all nodes in the list (excluding sentinels).
Sourcepub fn iter_with_sentinels<'alloc>(
&self,
alloc: &'alloc IDBoundAlloc<I>,
) -> EntityListIter<'alloc, I> ⓘ
pub fn iter_with_sentinels<'alloc>( &self, alloc: &'alloc IDBoundAlloc<I>, ) -> EntityListIter<'alloc, I> ⓘ
Create an iterator over all nodes in the list (including sentinels).
Sourcepub fn forall_with_sentinel(
&self,
alloc: &IDBoundAlloc<I>,
f: impl FnMut(I, &I::ObjectT) -> EntityListRes<I>,
) -> EntityListRes<I, ()>
pub fn forall_with_sentinel( &self, alloc: &IDBoundAlloc<I>, f: impl FnMut(I, &I::ObjectT) -> EntityListRes<I>, ) -> EntityListRes<I, ()>
Apply a function to all nodes in the list (including sentinels).