pub struct OrderCachedList<I: IOrderCachedListNodeID> {
pub head: I,
pub tail: I,
/* private fields */
}Expand description
Order-cached doubly-linked list.
Fields§
§head: IHead sentinel node ID. Order is always 0 and do not represent a valid item.
tail: ITail sentinel node ID. Order is always usize::MAX and does not represent a valid item.
Implementations§
Source§impl<I: IOrderCachedListNodeID> OrderCachedList<I>
impl<I: IOrderCachedListNodeID> OrderCachedList<I>
Sourcepub const HEAD_ORDER: usize = 0
pub const HEAD_ORDER: usize = 0
Order value of the head sentinel.
Sourcepub const TAIL_ORDER: usize = usize::MAX
pub const TAIL_ORDER: usize = usize::MAX
Order value of the tail sentinel.
Sourcepub const MAX_LEN: usize = Self::LEN_MASK
pub const MAX_LEN: usize = Self::LEN_MASK
Maximum length supported by the list: 2^(usize::BITS - 1) - 1.
Sourcepub fn new(alloc: &IDBoundAlloc<I>) -> Self
pub fn new(alloc: &IDBoundAlloc<I>) -> Self
Create a new empty order-cached list with given head and tail sentinels.
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 order_valid(&self) -> bool
pub fn order_valid(&self) -> bool
Check whether the order cache is valid.
Sourcepub fn invalidate_order(&self)
pub fn invalidate_order(&self)
Invalidate the order cache.
Sourcepub fn rebuild_order(&self, alloc: &IDBoundAlloc<I>)
pub fn rebuild_order(&self, alloc: &IDBoundAlloc<I>)
Rebuild the order cache regardless of its current validity.
Sourcepub fn get_node_order(&self, alloc: &IDBoundAlloc<I>, node: I) -> usize
pub fn get_node_order(&self, alloc: &IDBoundAlloc<I>, node: I) -> usize
Get the order of a node. If the order cache is invalid, it will be rebuilt first.
Sourcepub fn node_comes_before(&self, alloc: &IDBoundAlloc<I>, a: I, b: I) -> bool
pub fn node_comes_before(&self, alloc: &IDBoundAlloc<I>, a: I, b: I) -> bool
Check whether node a comes before node b in the list.
Sourcepub fn node_comes_after(&self, alloc: &IDBoundAlloc<I>, a: I, b: I) -> bool
pub fn node_comes_after(&self, alloc: &IDBoundAlloc<I>, a: I, b: I) -> bool
Check whether node a comes after node b in the list.
Sourcepub fn get_range(&self, alloc: &IDBoundAlloc<I>) -> EntityListRange<I>
pub fn get_range(&self, alloc: &IDBoundAlloc<I>) -> EntityListRange<I>
Get the range covering all nodes in the order-cached list (excluding sentinels).
Sourcepub fn get_range_with_sentinels(&self) -> EntityListRange<I>
pub fn get_range_with_sentinels(&self) -> EntityListRange<I>
Get the range covering all nodes including sentinels.
Sourcepub fn debug<'a>(
&self,
alloc: &'a IDBoundAlloc<I>,
) -> EntityListRangeDebug<'a, I>
pub fn debug<'a>( &self, alloc: &'a IDBoundAlloc<I>, ) -> EntityListRangeDebug<'a, I>
Create a debug view for this range.
Sourcepub fn iter<'a>(&self, alloc: &'a IDBoundAlloc<I>) -> EntityListIter<'a, I> ⓘ
pub fn iter<'a>(&self, alloc: &'a IDBoundAlloc<I>) -> EntityListIter<'a, I> ⓘ
Create an iterator over the nodes in the order-cached list.
Sourcepub fn iter_with_sentinels<'a>(
&self,
alloc: &'a IDBoundAlloc<I>,
) -> EntityListIter<'a, I> ⓘ
pub fn iter_with_sentinels<'a>( &self, alloc: &'a IDBoundAlloc<I>, ) -> EntityListIter<'a, I> ⓘ
Create an iterator over all nodes 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).
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.
§Order maintaining
If the order representation is Exact, the order cache will be invalidated unless the
unplugged node is the last node in the list. Otherwise, the order cache validity is left
unchanged.
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.
§Order maintaining
The order cache will be invalidated unless the new node is added at the end of the list.
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.
§Order maintaining
The order cache will be invalidated unless the node is the tail sentinel.
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. Will not invalidate order cache if possible.
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. Will invalidate order cache.
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. Will not invalidate order cache if possible.
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. Will invalidate order cache if repr is Exact.