Skip to content

Commit

Permalink
No, keep add_node_before, maintain the parallel; remove TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Oct 24, 2023
1 parent ed4afa1 commit 9bb1b49
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/hugr/hugrmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ pub trait HugrMut: HugrMutInternals {
self.hugr_mut().add_op_before(sibling, op)
}

/// Add a node to the graph as the previous sibling of another node.
///
/// The sibling node's parent becomes the new node's parent.
#[inline]
fn add_node_before(&mut self, sibling: Node, nodetype: NodeType) -> Result<Node, HugrError> {
self.valid_non_root(sibling)?;
self.hugr_mut().add_node_before(sibling, nodetype)
}

/// Add a node to the graph as the next sibling of another node.
///
/// The sibling node's parent becomes the new node's parent.
Expand Down Expand Up @@ -206,7 +215,11 @@ impl<T: RootTagged<RootHandle = Node> + AsMut<Hugr>> HugrMut for T {
}

fn add_op_before(&mut self, sibling: Node, op: impl Into<OpType>) -> Result<Node, HugrError> {
let node = self.as_mut().add_node(NodeType::open_extensions(op));
self.add_node_before(sibling, NodeType::open_extensions(op))
}

fn add_node_before(&mut self, sibling: Node, nodetype: NodeType) -> Result<Node, HugrError> {
let node = self.as_mut().add_node(nodetype);
self.as_mut()
.hierarchy
.insert_before(node.index, sibling.index)?;
Expand Down

0 comments on commit 9bb1b49

Please sign in to comment.