Struct SelfRefCol

Source
pub struct SelfRefCol<V, M, P>
where V: Variant, M: MemoryPolicy<V>, P: PinnedVec<Node<V>>,
{ /* 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>
where V: Variant, M: MemoryPolicy<V>, P: PinnedVec<Node<V>>,

Source

pub fn new() -> Self
where P: Default,

Creates a new empty collection.

Source

pub fn into_inner(self) -> (CoreCol<V, P>, MemoryState)

Breaks the self referential collection into its core collection and memory state.

Source

pub fn memory_state(&self) -> MemoryState

Memory state of the collection.

Source

pub fn memory(&self) -> &M

Memory policy of the collection.

Source

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.

Source

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.

Source

pub fn update_state(&mut self, state_changed: bool)

If state_changed is true, proceeds to the next memory state.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Clears the collection and changes the memory state.

Source

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.

Source

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.

Source

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>>§

Source

pub fn utilization(&self) -> Utilization

Returns current node utilization of the collection.

Source

pub fn len(&self) -> usize

Returns length of the self referential collection.

Source

pub fn is_empty(&self) -> bool

Returns whether or not the self referential collection is empty.

Source

pub fn nodes(&self) -> &P

Returns a reference to the underlying nodes storage.

Source

pub fn node(&self, node_ptr: &NodePtr<V>) -> &Node<V>

Returns a reference to the node with the given node_ptr.

Source

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.

Source

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.

Source

pub unsafe fn data_unchecked(&self, node_ptr: &NodePtr<V>) -> &V::Item

Returns a reference to the data.

§Panics

Panics if the node is already closed.

§Safety

Does not perform bounds check; hence, the caller must guarantee that the node_ptr belongs to (created from) this collection.

Source

pub fn ends(&self) -> &V::Ends

Returns a reference to the ends of the collection.

Source

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.

Source

pub fn nodes_mut(&mut self) -> &mut P

Returns a mutable reference to the underlying nodes storage.

Source

pub fn push(&mut self, data: V::Item) -> NodePtr<V>

Pushes the element with the given data and returns its pointer.

Source

pub unsafe fn data_mut_unchecked( &mut self, node_ptr: &NodePtr<V>, ) -> &mut V::Item

Returns a mutable reference to the data.

§Panics

Panics if the node is already closed.

§Safety

Does not perform bounds check; hence, the caller must guarantee that the node_ptr belongs to (created from) this collection.

Source

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.

Source

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.

Source

pub fn ends_mut(&mut self) -> &mut V::Ends

Returns a mutable reference to the ends of the collection.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<V, M, P> Default for SelfRefCol<V, M, P>
where V: Variant, M: MemoryPolicy<V>, P: PinnedVec<Node<V>> + Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<V, M, P> Deref for SelfRefCol<V, M, P>
where V: Variant, M: MemoryPolicy<V>, P: PinnedVec<Node<V>>,

Source§

type Target = CoreCol<V, P>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<V, M, P> DerefMut for SelfRefCol<V, M, P>
where V: Variant, M: MemoryPolicy<V>, P: PinnedVec<Node<V>>,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<V, M, P> From<(P, <V as Variant>::Ends)> for SelfRefCol<V, M, P>
where V: Variant, M: MemoryPolicy<V>, P: PinnedVec<Node<V>>,

Source§

fn from(value: (P, V::Ends)) -> Self

Converts to this type from the input type.
Source§

impl<const D: usize, R, V, P> From<SelfRefCol<V, MemoryReclaimNever, P>> for SelfRefCol<V, MemoryReclaimOnThreshold<D, V, R>, P>
where V: Variant, R: MemoryReclaimer<V>, P: PinnedVec<Node<V>>,

Source§

fn from(value: SelfRefCol<V, MemoryReclaimNever, P>) -> Self

Converts to this type from the input type.
Source§

impl<const D: usize, R, V, P> From<SelfRefCol<V, MemoryReclaimOnThreshold<D, V, R>, P>> for SelfRefCol<V, MemoryReclaimNever, P>
where V: Variant, R: MemoryReclaimer<V>, P: PinnedVec<Node<V>>,

Source§

fn from(value: SelfRefCol<V, MemoryReclaimOnThreshold<D, V, R>, P>) -> Self

Converts to this type from the input type.
Source§

impl<V, M, P> FromIterator<<V as Variant>::Item> for SelfRefCol<V, M, P>
where V: Variant, M: MemoryPolicy<V>, P: PinnedVec<Node<V>> + Default,

Source§

fn from_iter<I: IntoIterator<Item = V::Item>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<V, M, P> Freeze for SelfRefCol<V, M, P>
where M: Freeze, P: Freeze, <V as Variant>::Ends: Freeze,

§

impl<V, M, P> RefUnwindSafe for SelfRefCol<V, M, P>

§

impl<V, M, P> Send for SelfRefCol<V, M, P>
where M: Send, P: Send, <V as Variant>::Ends: Send,

§

impl<V, M, P> Sync for SelfRefCol<V, M, P>
where M: Sync, P: Sync, <V as Variant>::Ends: Sync,

§

impl<V, M, P> Unpin for SelfRefCol<V, M, P>
where M: Unpin, P: Unpin, <V as Variant>::Ends: Unpin,

§

impl<V, M, P> UnwindSafe for SelfRefCol<V, M, P>
where M: UnwindSafe, P: UnwindSafe, <V as Variant>::Ends: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> SoM<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
Source§

fn get_mut(&mut self) -> &mut T

Returns a mutable reference to self.
Source§

impl<T> SoR<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.