pub struct MultiPortGraph { /* private fields */ }
Expand description

An unlabelled port graph that allows multiple links to the same ports.

A port graph consists of a collection of nodes identified by a NodeIndex. Each node has an ordered sequence of input and output ports, identified by a PortIndex that is unique within the graph. To optimize for the most common use case, the number of input and output ports of a node must be specified when the node is created. Multiple connections to the same PortIndex can be distinguished by their SubportIndex.

When a node and its associated ports are removed their indices will be reused on a best effort basis when a new node is added. The indices of unaffected nodes and ports remain stable.

Implementations§

source§

impl MultiPortGraph

source

pub fn new() -> Self

Create a new empty MultiPortGraph.

source

pub fn with_capacity(nodes: usize, ports: usize) -> Self

Create a new empty MultiPortGraph with preallocated capacity.

source

pub fn as_portgraph(&self) -> &PortGraph

Returns a reference to the internal plain portgraph.

This graph exposes the copy nodes as well as the main nodes.

source

pub fn pg_main_node(&self, node: NodeIndex) -> NodeIndex

Given a node in the underlying flat portgraph, returns the main node for it.

If the node is not a copy node, returns the node itself.

Trait Implementations§

source§

impl Clone for MultiPortGraph

source§

fn clone(&self) -> MultiPortGraph

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MultiPortGraph

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for MultiPortGraph

source§

fn default() -> MultiPortGraph

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

impl From<MultiPortGraph> for PortGraph

source§

fn from(multi: MultiPortGraph) -> Self

Converts to this type from the input type.
source§

impl From<PortGraph> for MultiPortGraph

source§

fn from(graph: PortGraph) -> Self

Converts to this type from the input type.
source§

impl LinkMut for MultiPortGraph

Link an output port to an input port. Read more
Unlinks all connections to the port. If the port was connected, returns one of the ports it was connected to.
Links two nodes at an input and output port offsets. Read more
Links two nodes at an input and output port offsets. Read more
source§

fn insert_graph( &mut self, other: &impl LinkView ) -> Result<HashMap<NodeIndex, NodeIndex>, LinkError>

Inserts another graph into this graph. Read more
source§

impl LinkView for MultiPortGraph

§

type LinkEndpoint = SubportIndex

The identifier for the endpoints of a link.
§

type Neighbours<'a> = Neighbours<'a> where Self: 'a

Iterator over the neighbours of a node.
§

type NodeConnections<'a> = NodeConnections<'a> where Self: 'a

Iterator over the connections between two nodes.
Iterator over the links of a node. Returns pairs of source subport in the given node and target subport in the linked node.
Iterator over the links of a port. Returns pairs of source subport in the given ports and target subport in the linked port.
source§

fn get_connections( &self, from: NodeIndex, to: NodeIndex ) -> Self::NodeConnections<'_>

Returns an iterator over every pair of matching ports connecting from with to. Read more
Returns the port that the given port is linked to.
Iterates over the connected links of the node in the given direction. Read more
Iterates over the connected input and output links of the node in sequence.
source§

fn neighbours( &self, node: NodeIndex, direction: Direction ) -> Self::Neighbours<'_>

Iterates over neighbour nodes in the given direction. May contain duplicates if the graph has multiple links between nodes. Read more
source§

fn all_neighbours(&self, node: NodeIndex) -> Self::Neighbours<'_>

Iterates over the input and output neighbours of the node in sequence.
Returns the number of links between ports.
source§

fn get_connection( &self, from: NodeIndex, to: NodeIndex ) -> Option<(Self::LinkEndpoint, Self::LinkEndpoint)>

Checks whether there is a directed link between the two nodes and returns the first matching pair of ports. Read more
source§

fn connected(&self, from: NodeIndex, to: NodeIndex) -> bool

Checks whether there is a directed link between the two nodes. Read more
Return the link to the provided port, if not connected return None. If this port has multiple connected subports, an arbitrary one is returned.
Iterates over the connected input links of the node. Shorthand for LinkView::links.
Iterates over the connected output links of the node. Shorthand for LinkView::links.
source§

fn input_neighbours(&self, node: NodeIndex) -> Self::Neighbours<'_>

Iterates over the input neighbours of the node. Shorthand for LinkView::neighbours.
source§

fn output_neighbours(&self, node: NodeIndex) -> Self::Neighbours<'_>

Iterates over the output neighbours of the node. Shorthand for LinkView::neighbours.
source§

impl MultiMut for MultiPortGraph

Link an output subport to an input subport. Read more
Unlinks the port and returns the subport it was linked to. Returns None when the port was not linked.
source§

impl MultiView for MultiPortGraph

§

type NodeSubports<'a> = NodeSubports<'a> where Self: 'a

Iterator over all the subports of a node.
Return the subport linked to the given port. If the port is not connected, return None.
source§

fn subports( &self, node: NodeIndex, direction: Direction ) -> Self::NodeSubports<'_>

Iterates over all the subports of the node in the given direction.
source§

fn all_subports(&self, node: NodeIndex) -> Self::NodeSubports<'_>

Iterates over the input and output subports of the node in sequence.
source§

fn subport_inputs(&self, node: NodeIndex) -> Self::NodeSubports<'_>

Iterates over all the input subports of the node. Read more
source§

fn subport_outputs(&self, node: NodeIndex) -> Self::NodeSubports<'_>

Iterates over all the output subports of the node. Read more
source§

impl PartialEq for MultiPortGraph

source§

fn eq(&self, other: &MultiPortGraph) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PortMut for MultiPortGraph

source§

fn add_node(&mut self, incoming: usize, outgoing: usize) -> NodeIndex

Adds a node to the portgraph with a given number of input and output ports. Read more
source§

fn remove_node(&mut self, node: NodeIndex)

Remove a node from the port graph. All ports of the node will be unlinked and removed as well. Does nothing if the node does not exist. Read more
source§

fn clear(&mut self)

Removes all nodes and ports from the port graph.
source§

fn reserve(&mut self, nodes: usize, ports: usize)

Reserves enough capacity to insert at least the given number of additional nodes and ports. Read more
source§

fn set_num_ports<F>( &mut self, node: NodeIndex, incoming: usize, outgoing: usize, rekey: F )

Changes the number of ports of the node to the given incoming and outgoing counts. Read more
source§

fn compact_nodes<F>(&mut self, rekey: F)

Compacts the storage of nodes in the portgraph as much as possible. Note that node indices won’t necessarily be consecutive after this process. Read more
source§

fn swap_nodes(&mut self, a: NodeIndex, b: NodeIndex)

Swaps the indices of two nodes.
source§

fn compact_ports<F>(&mut self, rekey: F)

Compacts the storage of ports in the portgraph as much as possible. Note that indices won’t necessarily be consecutive after this process. Read more
source§

fn shrink_to_fit(&mut self)

Shrinks the underlying buffers to the fit the data. Read more
source§

impl PortView for MultiPortGraph

§

type Nodes<'a> = Nodes<'a> where Self: 'a

Iterator over the nodes of the graph.
§

type Ports<'a> = Ports<'a> where Self: 'a

Iterator over the ports of the graph.
§

type NodePorts<'a> = NodePorts where Self: 'a

Iterator over the ports of a node.
§

type NodePortOffsets<'a> = NodePortOffsets where Self: 'a

Iterator over the port offsets in a node.
source§

fn port_direction(&self, port: impl Into<PortIndex>) -> Option<Direction>

Returns the direction of the port.
source§

fn port_node(&self, port: impl Into<PortIndex>) -> Option<NodeIndex>

Returns the node that the port belongs to.
source§

fn port_offset(&self, port: impl Into<PortIndex>) -> Option<PortOffset>

Returns the index of a port within its node’s port list.
source§

fn port_index(&self, node: NodeIndex, offset: PortOffset) -> Option<PortIndex>

Returns the port index for a given node, direction, and offset.
source§

fn ports(&self, node: NodeIndex, direction: Direction) -> Self::NodePorts<'_>

Iterates over all the ports of the node in the given direction.
source§

fn all_ports(&self, node: NodeIndex) -> Self::NodePorts<'_>

Iterates over the input and output ports of the node in sequence.
source§

fn input(&self, node: NodeIndex, offset: usize) -> Option<PortIndex>

Returns the input port at the given offset in the node. Read more
source§

fn output(&self, node: NodeIndex, offset: usize) -> Option<PortIndex>

Returns the output port at the given offset in the node. Read more
source§

fn num_ports(&self, node: NodeIndex, direction: Direction) -> usize

Returns the number of ports of the node in the given direction.
source§

fn port_offsets( &self, node: NodeIndex, direction: Direction ) -> Self::NodePortOffsets<'_>

Iterates over all the port offsets of the node in the given direction. Read more
source§

fn all_port_offsets(&self, node: NodeIndex) -> Self::NodePortOffsets<'_>

Iterates over the input and output port offsets of the node in sequence.
source§

fn contains_node(&self, node: NodeIndex) -> bool

Returns whether the port graph contains the node.
source§

fn contains_port(&self, port: PortIndex) -> bool

Returns whether the port graph contains the port.
source§

fn is_empty(&self) -> bool

Returns whether the port graph has no nodes nor ports.
source§

fn node_count(&self) -> usize

Returns the number of nodes in the port graph.
source§

fn port_count(&self) -> usize

Returns the number of ports in the port graph.
source§

fn nodes_iter(&self) -> Self::Nodes<'_>

Iterates over the nodes in the port graph.
source§

fn ports_iter(&self) -> Self::Ports<'_>

Iterates over the ports in the port graph.
source§

fn node_capacity(&self) -> usize

Returns the capacity of the underlying buffer for nodes.
source§

fn port_capacity(&self) -> usize

Returns the capacity of the underlying buffer for ports.
source§

fn node_port_capacity(&self, node: NodeIndex) -> usize

Returns the allocated port capacity for a specific node. Read more
source§

fn inputs(&self, node: NodeIndex) -> Self::NodePorts<'_>

Iterates over all the input ports of the node. Read more
source§

fn outputs(&self, node: NodeIndex) -> Self::NodePorts<'_>

Iterates over all the output ports of the node. Read more
source§

fn num_inputs(&self, node: NodeIndex) -> usize

Returns the number of input ports of the node. Read more
source§

fn num_outputs(&self, node: NodeIndex) -> usize

Returns the number of output ports of the node. Read more
source§

fn input_offsets(&self, node: NodeIndex) -> Self::NodePortOffsets<'_>

Iterates over all the input port offsets of the node. Read more
source§

fn output_offsets(&self, node: NodeIndex) -> Self::NodePortOffsets<'_>

Iterates over all the output port offsets of the node. Read more
source§

impl StructuralPartialEq for MultiPortGraph

Auto Trait Implementations§

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
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
source§

impl<G> DotFormat for G
where G: LinkView,

source§

fn dot_format(&self) -> DotFormatter<'_, G>

Initialize a DotFormatter for the graph.
source§

fn dot_string(&self) -> String

Encode the graph in dot format.
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. 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<G> MermaidFormat for G
where G: LinkView,

source§

fn mermaid_format(&self) -> MermaidFormatter<'_, G>

Initialize a MermaidFormatter for the graph. Read more
source§

fn mermaid_string(&self) -> String

Encode the graph in mermaid format. See MermaidFormat::mermaid_format for more control over the output style. Read more
§

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

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

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

§

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

§

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.