PortMut

Trait PortMut 

Source
pub trait PortMut: PortView {
    // Required methods
    fn add_node(&mut self, incoming: usize, outgoing: usize) -> NodeIndex;
    fn remove_node(&mut self, node: NodeIndex);
    fn clear(&mut self);
    fn reserve(&mut self, nodes: usize, ports: usize);
    fn set_num_ports<F>(
        &mut self,
        node: NodeIndex,
        incoming: usize,
        outgoing: usize,
        rekey: F,
    )
       where F: FnMut(PortIndex, PortOperation);
    fn swap_nodes(&mut self, a: NodeIndex, b: NodeIndex);
    fn compact_nodes<F>(&mut self, rekey: F)
       where F: FnMut(NodeIndex, NodeIndex);
    fn compact_ports<F>(&mut self, rekey: F)
       where F: FnMut(PortIndex, PortIndex);
    fn shrink_to_fit(&mut self);
}
Expand description

Core capabilities for mutating a graph containing nodes and ports.

Required Methods§

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.

§Panics

Panics if the total number of ports exceeds u16::MAX.

§Example
let mut g: PortGraph = PortGraph::new();
let node = g.add_node(4, 3);
assert_eq!(g.inputs(node).count(), 4);
assert_eq!(g.outputs(node).count(), 3);
assert!(g.contains_node(node));
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.

§Example
let mut g: PortGraph = PortGraph::new();
let node0 = g.add_node(1, 1);
let node1 = g.add_node(1, 1);
let out0 = g.outputs(node0).nth(0).unwrap();
let out1 = g.outputs(node1).nth(0).unwrap();
let in0 = g.inputs(node0).nth(0).unwrap();
let in1 = g.inputs(node1).nth(0).unwrap();
g.link_ports(out0, in1);
g.link_ports(out1, in0);
g.remove_node(node0);
assert!(!g.contains_node(node0));
assert!(g.port_link(g.outputs(node1).nth(0).unwrap()).is_none());
assert!(g.port_link(g.inputs(node1).nth(0).unwrap()).is_none());
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.

This method does not take into account the length of the free list and might overallocate speculatively.

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.

Invalidates the indices of the node’s ports. If the number of incoming or outgoing ports is reduced, the ports are removed from the end of the port list.

Every time a port is moved, the rekey function will be called with its old and new index. If the port is removed, the new index will be None.

This operation is O(n) where n is the number of ports of the node.

Source

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

Swaps the indices of two nodes.

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.

Every time a node is moved, the rekey function will be called with its old and new index.

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.

Every time a port is moved, the rekey function will be called with is old and new index.

Source

fn shrink_to_fit(&mut self)

Shrinks the underlying buffers to the fit the data.

This does not alter existing indices.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<G: PortMut> PortMut for &mut G

Source§

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

Source§

fn remove_node(&mut self, node: NodeIndex)

Source§

fn clear(&mut self)

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

fn shrink_to_fit(&mut self)

Implementors§

Source§

impl<G: PortMut> PortMut for DynamicTopoConvexChecker<G>

Implement PortMut for DynamicTopoConvexChecker

Source§

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

Source§

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