Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Subgraph::copy_in_parent #182

Merged
merged 26 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7e132b7
Make is_multiport a method of LinkView
acl-cqc Jan 21, 2025
e88eeb3
Revert "Make is_multiport a method of LinkView"
acl-cqc Jan 21, 2025
ac60883
Add LinkView::endpoint_port
acl-cqc Jan 22, 2025
bfb2aed
Add SubGraph::copy_in_parent for any LinkMut, error+restore on non-mu…
acl-cqc Jan 22, 2025
666b3ff
Avoid double-copy by duplicating code for graph insertion
acl-cqc Jan 22, 2025
0113ca3
Remove unnecessary 'Clone' bounds
acl-cqc Jan 22, 2025
b5b7b58
refs.rs: implement {Port/Link/Multi}{View,Mut} for &mut G
acl-cqc Jan 22, 2025
6550cd7
First test, fix one-direction-only
acl-cqc Jan 22, 2025
1a5e392
Add test with edges over boundary; assert_same_for_nodes
acl-cqc Jan 22, 2025
83b9607
Test on MultiPortGraph
acl-cqc Jan 22, 2025
1b8faa4
Remove extraneous comment - Subgraph is not a LinkMut so impossible
acl-cqc Jan 22, 2025
093430b
fmt
acl-cqc Jan 22, 2025
f211e11
In error test, check nodes same before/after
acl-cqc Jan 22, 2025
46e2dbb
Revert "Add LinkView::endpoint_port"
acl-cqc Jan 22, 2025
e5d901c
Also remove endpoint_port for impl LinkMut for &mut G
acl-cqc Jan 22, 2025
bbaa70d
...and update to constrain by Into<PortIndex>
acl-cqc Jan 22, 2025
f227366
test_bad_boundary and test_multi: generalize to both directions
acl-cqc Jan 24, 2025
725af27
Separate test_c,py_in_parent_multi into _input and _output
acl-cqc Feb 3, 2025
090b661
Add comment about self-cycles
acl-cqc Feb 3, 2025
6d8fc63
Add CopySubgraphError, unwrap most LinkError's
acl-cqc Feb 3, 2025
99aca55
missing refs
acl-cqc Feb 5, 2025
b6cba8d
non-exhaustive error
acl-cqc Feb 5, 2025
4317f1f
Drop redundant Into<PortIndex> bound
acl-cqc Feb 5, 2025
21c1a09
docs, re-export CopySubgraphError
acl-cqc Feb 5, 2025
a2bd930
tidy imports
acl-cqc Feb 5, 2025
eeb5257
use expect
acl-cqc Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 75 additions & 3 deletions src/view/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
//! Note: The `auto_impl` crate would do all of this for us,
//! but it does not support GATs at the moment.

use crate::{Direction, NodeIndex, PortIndex, PortOffset};
use crate::{Direction, LinkError, NodeIndex, PortIndex, PortOffset};

use delegate::delegate;

use super::{LinkView, MultiView, PortView};
use super::{LinkMut, LinkView, MultiView, PortMut, PortView};

impl<G: PortView> PortView for &G {
delegate! {
Expand Down Expand Up @@ -37,6 +37,34 @@ impl<G: PortView> PortView for &G {
}
}

impl<G: PortView> PortView for &mut G {
delegate! {
to (&**self) {
fn port_direction(&self, port: impl Into<PortIndex>) -> Option<Direction>;
fn port_node(&self, port: impl Into<PortIndex>) -> Option<NodeIndex>;
fn port_offset(&self, port: impl Into<PortIndex>) -> Option<PortOffset>;
fn port_index(&self, node: NodeIndex, offset: PortOffset) -> Option<PortIndex>;
fn ports(&self, node: NodeIndex, direction: Direction) -> impl Iterator<Item = PortIndex> + Clone;
fn all_ports(&self, node: NodeIndex) -> impl Iterator<Item = PortIndex> + Clone;
fn input(&self, node: NodeIndex, offset: usize) -> Option<PortIndex>;
fn output(&self, node: NodeIndex, offset: usize) -> Option<PortIndex>;
fn num_ports(&self, node: NodeIndex, direction: Direction) -> usize;
fn port_offsets(&self, node: NodeIndex, direction: Direction) -> impl Iterator<Item = PortOffset> + Clone;
fn all_port_offsets(&self, node: NodeIndex) -> impl Iterator<Item = PortOffset> + Clone;
fn contains_node(&self, node: NodeIndex) -> bool;
fn contains_port(&self, port: PortIndex) -> bool;
fn is_empty(&self) -> bool;
fn node_count(&self) -> usize;
fn port_count(&self) -> usize;
fn nodes_iter(&self) -> impl Iterator<Item = NodeIndex> + Clone;
fn ports_iter(&self) -> impl Iterator<Item = PortIndex> + Clone;
fn node_capacity(&self) -> usize;
fn port_capacity(&self) -> usize;
fn node_port_capacity(&self, node: NodeIndex) -> usize;
}
}
}

impl<G: LinkView> LinkView for &G {
type LinkEndpoint = G::LinkEndpoint;

Expand All @@ -53,6 +81,22 @@ impl<G: LinkView> LinkView for &G {
}
}

impl<G: LinkView> LinkView for &mut G {
type LinkEndpoint = G::LinkEndpoint;

delegate! {
to (&**self) {
fn get_connections(&self, from: NodeIndex, to: NodeIndex) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone;
fn port_links(&self, port: PortIndex) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone;
fn links(&self, node: NodeIndex, direction: Direction) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone;
fn all_links(&self, node: NodeIndex) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone;
fn neighbours(&self, node: NodeIndex, direction: Direction) -> impl Iterator<Item = NodeIndex> + Clone;
fn all_neighbours(&self, node: NodeIndex) -> impl Iterator<Item = NodeIndex> + Clone;
fn link_count(&self) -> usize;
}
}
}

impl<G: MultiView> MultiView for &G {
delegate! {
to (*self) {
Expand All @@ -63,4 +107,32 @@ impl<G: MultiView> MultiView for &G {
}
}

// TODO: PortMut, LinkMut, MultiMut
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add MultiMut too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, also MultiView for &mut G

impl<G: PortMut> PortMut for &mut G {
delegate! {
to (*self) {
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: FnMut(PortIndex, crate::portgraph::PortOperation)>(&mut self, node: NodeIndex, incoming: usize, outgoing: usize, rekey: F);
fn swap_nodes(&mut self, a: NodeIndex, b: NodeIndex);
fn compact_nodes<F: FnMut(NodeIndex, NodeIndex)>(&mut self, rekey: F);
fn compact_ports<F: FnMut(PortIndex, PortIndex)>(&mut self, rekey: F);
fn shrink_to_fit(&mut self);
}
}
}

impl<G: LinkMut> LinkMut for &mut G {
delegate! {
to (*self) {
fn link_ports(
&mut self,
port_a: PortIndex,
port_b: PortIndex,
) -> Result<(Self::LinkEndpoint, Self::LinkEndpoint), LinkError>;

fn unlink_port(&mut self, port: PortIndex) -> Option<Self::LinkEndpoint>;
}
}
}
Loading
Loading