pub struct SelfRefCol<V, M, P>{ /* private fields */ }
Expand description
SelfRefCol
is a core data structure to conveniently build safe and efficient self referential collections, such as linked lists and trees.
Implementations§
Source§impl<V, M, P> SelfRefCol<V, M, P>
impl<V, M, P> SelfRefCol<V, M, P>
Sourcepub fn into_inner(self) -> (CoreCol<V, P>, MemoryState)
pub fn into_inner(self) -> (CoreCol<V, P>, MemoryState)
Breaks the self referential collection into its core collection and memory state.
Sourcepub fn memory_state(&self) -> MemoryState
pub fn memory_state(&self) -> MemoryState
Memory state of the collection.
Sourcepub fn close_and_reclaim(&mut self, node_ptr: &NodePtr<V>) -> V::Item
pub fn close_and_reclaim(&mut self, node_ptr: &NodePtr<V>) -> V::Item
Closes the node with the given node_ptr
, returns its taken out value,
and reclaims closed nodes if necessary.
Sourcepub fn reclaim_from_closed_node(&mut self, node_ptr: &NodePtr<V>) -> bool
pub fn reclaim_from_closed_node(&mut self, node_ptr: &NodePtr<V>) -> bool
Succeeding the operation of closing of node with the given node_ptr
,
reclaims closed nodes if necessary.
Returns whether the memory state changed.
Sourcepub fn update_state(&mut self, state_changed: bool)
pub fn update_state(&mut self, state_changed: bool)
If state_changed
is true, proceeds to the next memory state.
Sourcepub fn node_from_idx(&self, idx: &NodeIdx<V>) -> Option<&Node<V>>
pub fn node_from_idx(&self, idx: &NodeIdx<V>) -> Option<&Node<V>>
Returns a reference to the node with the given NodeIdx
;
returns None if the index is invalid.
Sourcepub fn try_node_from_idx(
&self,
idx: &NodeIdx<V>,
) -> Result<&Node<V>, NodeIdxError>
pub fn try_node_from_idx( &self, idx: &NodeIdx<V>, ) -> Result<&Node<V>, NodeIdxError>
Tries to create a reference to the node with the given NodeIdx
;
returns the error if the index is invalid.
Sourcepub fn node_idx_error(&self, idx: &NodeIdx<V>) -> Option<NodeIdxError>
pub fn node_idx_error(&self, idx: &NodeIdx<V>) -> Option<NodeIdxError>
Returns the node index error if the index is invalid. Returns None if it is valid.
Sourcepub fn try_get_ptr(&self, idx: &NodeIdx<V>) -> Result<NodePtr<V>, NodeIdxError>
pub fn try_get_ptr(&self, idx: &NodeIdx<V>) -> Result<NodePtr<V>, NodeIdxError>
Tries to get a valid pointer to the node with the given NodeIdx
;
returns the error if the index is invalid.
Sourcepub fn get_ptr(&self, idx: &NodeIdx<V>) -> Option<NodePtr<V>>
pub fn get_ptr(&self, idx: &NodeIdx<V>) -> Option<NodePtr<V>>
Tries to get a valid pointer to the node with the given NodeIdx
;
returns None if the index is invalid.
Sourcepub fn node_mut_from_idx(&mut self, idx: &NodeIdx<V>) -> Option<&mut Node<V>>
pub fn node_mut_from_idx(&mut self, idx: &NodeIdx<V>) -> Option<&mut Node<V>>
Returns a mutable reference to the node with the given NodeIdx
;
returns None if the index is invalid.
Sourcepub fn try_node_mut_from_idx(
&mut self,
idx: &NodeIdx<V>,
) -> Result<&mut Node<V>, NodeIdxError>
pub fn try_node_mut_from_idx( &mut self, idx: &NodeIdx<V>, ) -> Result<&mut Node<V>, NodeIdxError>
Tries to create a mutable reference to the node with the given NodeIdx
;
returns the error if the index is invalid.
Sourcepub fn push_get_idx(&mut self, data: V::Item) -> NodeIdx<V>
pub fn push_get_idx(&mut self, data: V::Item) -> NodeIdx<V>
Pushes the element with the given data
and returns its index.
Methods from Deref<Target = CoreCol<V, P>>§
Sourcepub fn utilization(&self) -> Utilization
pub fn utilization(&self) -> Utilization
Returns current node utilization of the collection.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether or not the self referential collection is empty.
Sourcepub fn node(&self, node_ptr: &NodePtr<V>) -> &Node<V>
pub fn node(&self, node_ptr: &NodePtr<V>) -> &Node<V>
Returns a reference to the node with the given node_ptr
.
Sourcepub fn position_of(&self, node_ptr: &NodePtr<V>) -> Option<usize>
pub fn position_of(&self, node_ptr: &NodePtr<V>) -> Option<usize>
Returns the position of the node with the given node_ptr
,
None if the pointer is not valid.
Sourcepub fn position_of_unchecked(&self, node_ptr: &NodePtr<V>) -> usize
pub fn position_of_unchecked(&self, node_ptr: &NodePtr<V>) -> usize
Returns the position of the node with the given node_ptr
.
§Panics
Panics if the pointer is not valid.
Sourcepub unsafe fn data_unchecked(&self, node_ptr: &NodePtr<V>) -> &V::Item
pub unsafe fn data_unchecked(&self, node_ptr: &NodePtr<V>) -> &V::Item
Sourcepub fn node_ptr_at_pos(&self, node_position: usize) -> NodePtr<V>
pub fn node_ptr_at_pos(&self, node_position: usize) -> NodePtr<V>
Returns the pointer of the element with the given node_position
in the underlying nodes storage.
§Panics
Panics if the node_position
is out of bounds.
Sourcepub fn nodes_mut(&mut self) -> &mut P
pub fn nodes_mut(&mut self) -> &mut P
Returns a mutable reference to the underlying nodes storage.
Sourcepub fn push(&mut self, data: V::Item) -> NodePtr<V>
pub fn push(&mut self, data: V::Item) -> NodePtr<V>
Pushes the element with the given data
and returns its pointer.
Sourcepub unsafe fn data_mut_unchecked(
&mut self,
node_ptr: &NodePtr<V>,
) -> &mut V::Item
pub unsafe fn data_mut_unchecked( &mut self, node_ptr: &NodePtr<V>, ) -> &mut V::Item
Sourcepub fn close(&mut self, node_ptr: &NodePtr<V>) -> V::Item
pub fn close(&mut self, node_ptr: &NodePtr<V>) -> V::Item
Closes the node at the given node_ptr
and returns its data.
§Panics
Panics if the node was already closed.
Sourcepub fn close_if_active(&mut self, node_ptr: &NodePtr<V>) -> Option<V::Item>
pub fn close_if_active(&mut self, node_ptr: &NodePtr<V>) -> Option<V::Item>
Closes the node at the given node_ptr
and returns its data the node was active.
Does nothing and returns None if the node was already closed.
Sourcepub fn ends_mut(&mut self) -> &mut V::Ends
pub fn ends_mut(&mut self) -> &mut V::Ends
Returns a mutable reference to the ends of the collection.
Sourcepub fn node_mut(&mut self, node_ptr: &NodePtr<V>) -> &mut Node<V>
pub fn node_mut(&mut self, node_ptr: &NodePtr<V>) -> &mut Node<V>
Returns a mutable reference to the node with the given node_ptr
.