From 228b51fe7941e2b180ee3ea99dfea4bfcbd6770b Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 4 Aug 2023 10:11:24 +0800 Subject: splone: fix the bug of finding the wrong node * chain/src/item/default/splone.rs: A function for finding the node to plant used to ignore the condition that the children should match. Now this is fixed. --- chain/src/item/default/splone.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'chain/src') diff --git a/chain/src/item/default/splone.rs b/chain/src/item/default/splone.rs index 9da156a..f540000 100644 --- a/chain/src/item/default/splone.rs +++ b/chain/src/item/default/splone.rs @@ -555,6 +555,8 @@ impl DefaultForest> { } if node_label.clone_index().is_some() { + let node_children = self.children_of(node)?; + let mut parents = self.parents_of(node)?; #[cfg(debug_assertions)] @@ -562,13 +564,29 @@ impl DefaultForest> { let packed = parents.next().unwrap().node(); - for clone in self.children_of(packed)? { + 'clone_loop: for clone in self.children_of(packed)? { let degree = self.degree(clone)?; if degree == 0 { return Ok(Some(clone)); } + if degree <= edge_index { + continue; + } + + if clone != node { + for (clone_child, child) in self + .children_of(clone)? + .zip(node_children.clone()) + .take(edge_index + 1) + { + if clone_child != child { + continue 'clone_loop; + } + } + } + if degree >= edge_index + 2 { let index_child = self.nth_child(clone, edge_index + 1)?; @@ -706,7 +724,7 @@ impl DefaultForest> { // we add no child to parent.edge()-th child here. let cloned = self.clone_node(parent.node(), parent.edge(), false)?; - dbg!(cloned, parent, new_child); + // dbg!(cloned, parent, new_child); let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); -- cgit v1.2.3-18-g5258