From 987c84f3454c687cca0efe0d471fcf00e052ecab Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sun, 12 Feb 2023 12:07:34 +0800 Subject: Added the functionality of split or clone. I need more than the ability to clone nodes: I also need to split the nodes. Now this seems to be correctly added. --- chain/src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'chain/src/lib.rs') diff --git a/chain/src/lib.rs b/chain/src/lib.rs index 916678f..745ad5a 100644 --- a/chain/src/lib.rs +++ b/chain/src/lib.rs @@ -12,9 +12,6 @@ pub mod atom; pub mod item; -// TODO: We need a module for items, that serve the role of the -// forests now. - use graph::{error::Error as GError, LabelExtGraph}; use item::default::Error as ForestError; @@ -67,6 +64,13 @@ impl core::fmt::Display for Edge { } } +// TODO: Define an enumeration that stands for either an edge or a +// "phantom" edge. +// +// A phantom edge will be ignored when adding edges. The phantom +// edges will be used to determine the acceptance of a node, when and +// only when that new node turns out to have no children. + /// Each derivation is a concatenation of two items, so there are two /// layers. But some items have no children and are accepting, in /// which case we just skip that item completely, for performance @@ -179,7 +183,14 @@ pub trait Chain: LabelExtGraph { /// Take the union of all derivatives. fn union(&mut self, der_iter: Self::DerIter) -> Result, Self::Error> { // REVIEW: Find a way to avoid allocations. - Collapsed::<_, Self>::collapse(der_iter, self).collect() + Collapsed::<_, Self>::collapse(der_iter, self) + .collect::, Self::Error>>() + .map(|mut v| { + v.retain(|(_, target)| { + *target == 0 || matches!(self.degree(*target), Ok(deg) if deg != 0) + }); + v + }) } /// Use chain rule to compute the derivative with respect to a -- cgit v1.2.3-18-g5258