From e8ea01319b3a9032a3f4f69f65e9ca96562b87b9 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sun, 22 Jan 2023 11:49:47 +0800 Subject: forest: clone correctly Now the forest can detect if a node is packed or cloned, and correctly clones a node in those circumstances. But it still needs to be tested. --- chain/src/default.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'chain/src/default.rs') diff --git a/chain/src/default.rs b/chain/src/default.rs index b9d7fe6..22befff 100644 --- a/chain/src/default.rs +++ b/chain/src/default.rs @@ -10,10 +10,7 @@ use crate::atom::{Atom, DefaultAtom}; use core::fmt::Display; use forest::{default::DefaultForest, Forest}; use grammar::{Error as GrammarError, GrammarLabel, GrammarLabelType, TNT}; -#[allow(unused_imports)] -use graph::{ - labelled::DLGBuilder, Builder, DLGraph, Graph, LabelExtGraph, LabelGraph, ParentsGraph, -}; +use graph::{labelled::DLGBuilder, Builder, DLGraph, Graph, LabelExtGraph, LabelGraph}; use std::collections::{HashMap as Map, TryReserveError}; @@ -156,11 +153,13 @@ impl Iterator for DerIter { None } } else { - self.index = DerIterIndex::Single(0); + // If the zero-th element is present, we will + // advance the index to one; if it is not present, + // we will stop iteration. In each case we can + // safely set the index to one. + self.index = DerIterIndex::Single(1); if let Some((edge, to)) = self.singles.first() { - self.index = DerIterIndex::Single(1); - Some(TwoLayers::One(*edge, *to)) } else { None @@ -776,15 +775,7 @@ mod test_chain { println!("repeating {repeat_times} times"); - let input = { - let mut result = Vec::with_capacity(input_template.len() * repeat_times); - - for _ in 0..repeat_times { - result.extend(input_template.iter().copied()); - } - - result - }; + let input = input_template.repeat(repeat_times); let start = std::time::Instant::now(); -- cgit v1.2.3-18-g5258