pub struct NodeIdx<V: Variant> { /* private fields */ }Expand description
A node index providing safe and constant time access to elements of the self referential collection.
Implementations§
Source§impl<V> NodeIdx<V>where
V: Variant,
impl<V> NodeIdx<V>where
V: Variant,
Sourcepub fn new(state: MemoryState, node_ptr: NodePtr<V>) -> Self
pub fn new(state: MemoryState, node_ptr: NodePtr<V>) -> Self
Creates a new index for the element at the given node_ptr
and the collection with the given state.
Sourcepub fn is_in_state(self, state: MemoryState) -> bool
pub fn is_in_state(self, state: MemoryState) -> bool
Checks whether or not the state of the index matches that of this index.
Sourcepub unsafe fn get_ptr(
self,
collection_state: MemoryState,
) -> Option<*mut Node<V>>
pub unsafe fn get_ptr( self, collection_state: MemoryState, ) -> Option<*mut Node<V>>
Returns the node pointer if the index is in the same state as the collection_state,
None otherwise.
§SAFETY
This method is unsafe as NodeIdx implements Send and Sync.
It is safe dereference the received pointer if we know that is_valid_for(col) would
return true where col is the collection that this pointer is created from.
Sourcepub fn is_valid_for<M, P>(self, collection: &SelfRefCol<V, M, P>) -> bool
pub fn is_valid_for<M, P>(self, collection: &SelfRefCol<V, M, P>) -> bool
Returns true only if this index is valid for the given collection.
A node index is valid iff it satisfies the following two conditions:
- It is created from the given
collection. - Memory state of the
collectionhas not changed since this index was created.
It is safe to use the unsafe methods of NodeIdx if is_valid_for(col)
returns true where col is the collection that the index is created from.
Sourcepub fn node<M, P>(self, collection: &SelfRefCol<V, M, P>) -> Option<&Node<V>>
pub fn node<M, P>(self, collection: &SelfRefCol<V, M, P>) -> Option<&Node<V>>
Returns a reference to the node that this NodeIdx corresponds to;
returns None if the index is invalid.
See Self::is_valid_for for validity conditions.