summaryrefslogtreecommitdiff
path: root/chain/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'chain/src/lib.rs')
-rw-r--r--chain/src/lib.rs19
1 files changed, 15 insertions, 4 deletions
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<Edge> {
/// Take the union of all derivatives.
fn union(&mut self, der_iter: Self::DerIter) -> Result<Vec<(Edge, usize)>, Self::Error> {
// REVIEW: Find a way to avoid allocations.
- Collapsed::<_, Self>::collapse(der_iter, self).collect()
+ Collapsed::<_, Self>::collapse(der_iter, self)
+ .collect::<Result<Vec<(Edge, usize)>, 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