summaryrefslogtreecommitdiff
path: root/chain/src/item/default
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-08-04 10:11:24 +0800
committerJSDurand <mmemmew@gmail.com>2023-08-04 10:11:24 +0800
commit228b51fe7941e2b180ee3ea99dfea4bfcbd6770b (patch)
treeb12ba3720ae17c681c5f692d223bb3fea98eecac /chain/src/item/default
parent81a127bd5c432b36804af0d306980d283825e21d (diff)
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.
Diffstat (limited to 'chain/src/item/default')
-rw-r--r--chain/src/item/default/splone.rs22
1 files changed, 20 insertions, 2 deletions
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<ForestLabel<GrammarLabel>> {
}
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<ForestLabel<GrammarLabel>> {
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<ForestLabel<GrammarLabel>> {
// 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);