pub struct GraphTransaction<'a, T> { /* private fields */ }Expand description
Tracks changes and provides rollback capability
Implementations§
Source§impl<'a, T> GraphTransaction<'a, T>
impl<'a, T> GraphTransaction<'a, T>
pub fn new(graph: &'a mut Graph<T>) -> Self
pub fn commit(self) -> TransactionResult<T>
pub fn commit_with( self, validator: Option<&dyn Fn(&Graph<T>) -> bool>, ) -> TransactionResult<T>
pub fn len(&self) -> usize
pub fn add_node(&mut self, node: GraphNode<T>) -> usize
pub fn attach(&mut self, from: usize, to: usize)
pub fn detach(&mut self, from: usize, to: usize)
pub fn change_direction(&mut self, index: usize, direction: Direction)
pub fn rollback(self) -> Vec<ReplayStep<T>>
pub fn replay(&mut self, steps: Vec<ReplayStep<T>>)
pub fn is_valid(&self) -> bool
pub fn set_cycles(&mut self)
pub fn get_insertion_steps( &self, source_idx: usize, target_idx: usize, new_node_idx: usize, ) -> Vec<InsertStep>
Sourcepub fn random_source_node(&self) -> Option<&GraphNode<T>>
pub fn random_source_node(&self) -> Option<&GraphNode<T>>
The below functions are used to get random nodes from the graph. These are useful for creating connections between nodes. Neither of these functions will return an edge node. This is because edge nodes are not valid source or target nodes for connections as they they only allow one incoming and one outgoing connection, thus they can’t be used to create new connections. Instread, edge nodes are used to represent the weights of the connections
Get a random node that can be used as a source node for a connection. A source node can be either an input or a vertex node.
Sourcepub fn random_target_node(&self) -> Option<&GraphNode<T>>
pub fn random_target_node(&self) -> Option<&GraphNode<T>>
Get a random node that can be used as a target node for a connection. A target node can be either an output or a vertex node.
Methods from Deref<Target = Graph<T>>§
Sourcepub fn get(&self, index: usize) -> Option<&GraphNode<T>>
pub fn get(&self, index: usize) -> Option<&GraphNode<T>>
Returns a reference to the node at the specified index.