Struct GraphTransaction

Source
pub struct GraphTransaction<'a, T> { /* private fields */ }
Expand description

Tracks changes and provides rollback capability

Implementations§

Source§

impl<'a, T> GraphTransaction<'a, T>

Source

pub fn new(graph: &'a mut Graph<T>) -> Self

Source

pub fn commit(self) -> TransactionResult<T>

Source

pub fn commit_with( self, validator: Option<&dyn Fn(&Graph<T>) -> bool>, ) -> TransactionResult<T>

Source

pub fn len(&self) -> usize

Source

pub fn add_node(&mut self, node: GraphNode<T>) -> usize

Source

pub fn attach(&mut self, from: usize, to: usize)

Source

pub fn detach(&mut self, from: usize, to: usize)

Source

pub fn change_direction(&mut self, index: usize, direction: Direction)

Source

pub fn rollback(self) -> Vec<ReplayStep<T>>

Source

pub fn replay(&mut self, steps: Vec<ReplayStep<T>>)

Source

pub fn is_valid(&self) -> bool

Source

pub fn set_cycles(&mut self)

Source

pub fn get_insertion_steps( &self, source_idx: usize, target_idx: usize, new_node_idx: usize, ) -> Vec<InsertStep>

Source

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.

Source

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

Source

pub fn len(&self) -> usize

Returns the number of nodes in the graph.

Source

pub fn is_empty(&self) -> bool

Returns true if the graph is empty.

Source

pub fn get(&self, index: usize) -> Option<&GraphNode<T>>

Returns a reference to the node at the specified index.

Source

pub fn iter(&self) -> impl Iterator<Item = &GraphNode<T>>

iterates over the nodes in the graph. The nodes are returned in the order they were added, so there is no real order to this iterator.

Source

pub fn get_cycles(&self, index: usize) -> Vec<usize>

Get the cycles in the graph that include the node at the specified index.

§Arguments
  • index: The index of the node to get the cycles for.

Trait Implementations§

Source§

impl<'a, T> Deref for GraphTransaction<'a, T>

Source§

type Target = Graph<T>

The resulting type after dereferencing.
Source§

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

Dereferences the value.

Auto Trait Implementations§

§

impl<'a, T> Freeze for GraphTransaction<'a, T>

§

impl<'a, T> RefUnwindSafe for GraphTransaction<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for GraphTransaction<'a, T>
where T: Send,

§

impl<'a, T> Sync for GraphTransaction<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for GraphTransaction<'a, T>

§

impl<'a, T> !UnwindSafe for GraphTransaction<'a, T>

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V