PortGraph

Struct PortGraph 

Source
pub struct PortGraph<N: Unsigned = u32, P: Unsigned = u32, PO: Unsigned = u16> { /* private fields */ }
Expand description

An unlabelled port graph.

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.

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. PortGraph::compact_nodes and PortGraph::compact_ports to eliminate fragmentation in the index space.

Implementations§

Source§

impl<N: Unsigned, P: Unsigned, PO: Unsigned> PortGraph<N, P, PO>

Source

pub fn new() -> Self

Create a new empty PortGraph.

Source

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

Create a new empty PortGraph with preallocated capacity.

Trait Implementations§

Source§

impl<N: Clone + Unsigned, P: Clone + Unsigned, PO: Clone + Unsigned> Clone for PortGraph<N, P, PO>

Source§

fn clone(&self) -> PortGraph<N, P, PO>

Returns a duplicate 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<PO: Unsigned> Debug for PortGraph<u32, u32, PO>

Source§

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

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

impl<N: Unsigned, P: Unsigned, PO: Unsigned> Default for PortGraph<N, P, PO>

Source§

fn default() -> Self

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<PO: Unsigned> LinkMut for PortGraph<u32, u32, PO>

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<PortOffsetBase = Self::PortOffsetBase>, ) -> Result<HashMap<NodeIndex, NodeIndex>, LinkError<Self::PortOffsetBase>>

Inserts another graph into this graph. Read more
Source§

impl<PO: Unsigned> LinkView for PortGraph<u32, u32, PO>

Source§

type LinkEndpoint = PortIndex

The identifier for the endpoints of a link.
Returns the port (or ports if this is a MultiView) that the given port is linked to.
Returns the number of links between ports.
Source§

fn get_connections( &self, from: NodeIndex, to: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone

Returns an iterator over every pair of matching ports connecting from to to, i.e. in that direction. Read more
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, ) -> impl Iterator<Item = NodeIndex> + Clone

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, ) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over the input and output neighbours of the node in sequence.
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(Direction::Incoming).
Iterates over the connected output links of the node. Shorthand for LinkView::links(Direction::Outgoing)..
Source§

fn input_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over the input neighbours of the node. Read more
Source§

fn output_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over the output neighbours of the node. Read more
Source§

impl<N: PartialEq + Unsigned, P: PartialEq + Unsigned, PO: PartialEq + Unsigned> PartialEq for PortGraph<N, P, PO>

Source§

fn eq(&self, other: &PortGraph<N, P, PO>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<PO: Unsigned> PortMut for PortGraph<u32, u32, PO>

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<PO: Unsigned> PortView for PortGraph<u32, u32, PO>

Source§

type PortOffsetBase = PO

The base unsigned integer type for port offsets.
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<PO>>

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

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

Returns the port index for a given node and offset.
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 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 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 ports( &self, node: NodeIndex, direction: Direction, ) -> impl Iterator<Item = PortIndex> + Clone

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

fn all_ports(&self, node: NodeIndex) -> impl Iterator<Item = PortIndex> + Clone

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

fn port_offsets( &self, node: NodeIndex, direction: Direction, ) -> impl Iterator<Item = PortOffset<PO>> + Clone

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

fn all_port_offsets( &self, node: NodeIndex, ) -> impl Iterator<Item = PortOffset<PO>> + Clone

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

fn nodes_iter(&self) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over the nodes in the port graph.
Source§

fn ports_iter(&self) -> impl Iterator<Item = PortIndex> + Clone

Iterates over the ports in the port graph.
Source§

fn inputs(&self, node: NodeIndex) -> impl Iterator<Item = PortIndex> + Clone

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

fn outputs(&self, node: NodeIndex) -> impl Iterator<Item = PortIndex> + Clone

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, ) -> impl Iterator<Item = PortOffset<Self::PortOffsetBase>> + Clone

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

fn output_offsets( &self, node: NodeIndex, ) -> impl Iterator<Item = PortOffset<Self::PortOffsetBase>> + Clone

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

impl<N: Unsigned, P: Unsigned, PO: Unsigned> StructuralPartialEq for PortGraph<N, P, PO>

Auto Trait Implementations§

§

impl<N, P, PO> Freeze for PortGraph<N, P, PO>
where N: Freeze,

§

impl<N, P, PO> RefUnwindSafe for PortGraph<N, P, PO>

§

impl<N, P, PO> Send for PortGraph<N, P, PO>
where PO: Send, N: Send, P: Send,

§

impl<N, P, PO> Sync for PortGraph<N, P, PO>
where PO: Sync, N: Sync, P: Sync,

§

impl<N, P, PO> Unpin for PortGraph<N, P, PO>
where PO: Unpin, N: Unpin, P: Unpin,

§

impl<N, P, PO> UnwindSafe for PortGraph<N, P, PO>
where PO: UnwindSafe, N: UnwindSafe, P: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

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

impl<T> FmtForward for T

Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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
Source§

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

Source§

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

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

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

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

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

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

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

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

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

impl<T> Tap for T

Source§

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

Immutable access to a value. Read more
Source§

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

Mutable access to a value. Read more
Source§

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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,

Source§

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

impl<T> TryConv for T

Source§

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

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.