summaryrefslogtreecommitdiff
path: root/chain/src/lib.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-02-12 12:07:34 +0800
committerJSDurand <mmemmew@gmail.com>2023-02-12 12:07:34 +0800
commit987c84f3454c687cca0efe0d471fcf00e052ecab (patch)
tree04b9cf073a12adfb5d07ae308c3809e88cf4ebd2 /chain/src/lib.rs
parent265ff8f87dc7392fdf701f811eb2bf54d7bc6678 (diff)
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.
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