Struct orx_selfref_col::SelfRefCol
source · 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 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 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 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.
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.
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 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
.
sourcepub fn move_node(&mut self, closed_position: usize, active_position: usize)
pub fn move_node(&mut self, closed_position: usize, active_position: usize)
Swaps the closed node at the closed_position
with the active node
at the active_position
.
sourcepub fn swap_data(
&mut self,
node_ptr: &NodePtr<V>,
new_value: V::Item,
) -> V::Item
pub fn swap_data( &mut self, node_ptr: &NodePtr<V>, new_value: V::Item, ) -> V::Item
Swaps the underlying data of the element at the given node_ptr
with the new_value
,
and returns the old value.
§Panics
Panics if the node was already closed.
sourcepub fn append_nodes(&mut self, nodes: SplitVec<Node<V>, Recursive>)
pub fn append_nodes(&mut self, nodes: SplitVec<Node<V>, Recursive>)
Appends the nodes
to this collection.