From 3d0b63baa764a7eee729bf884ba70179ed43a0a4 Mon Sep 17 00:00:00 2001 From: Matthias Meissner Date: Tue, 17 Oct 2023 19:50:59 +0200 Subject: [PATCH] remove obsolete tagged_tree module --- nemo-physical/src/util.rs | 2 - nemo-physical/src/util/tagged_tree.rs | 115 -------------------------- 2 files changed, 117 deletions(-) delete mode 100644 nemo-physical/src/util/tagged_tree.rs diff --git a/nemo-physical/src/util.rs b/nemo-physical/src/util.rs index 65385df37..6d819a73e 100644 --- a/nemo-physical/src/util.rs +++ b/nemo-physical/src/util.rs @@ -1,8 +1,6 @@ //! This module collects miscellaneous functionality. pub mod mapping; -pub mod tagged_tree; -pub use tagged_tree::TaggedTree; /// A macro that generates forwarding macros to dispatch along /// datatype-tagged enums. diff --git a/nemo-physical/src/util/tagged_tree.rs b/nemo-physical/src/util/tagged_tree.rs deleted file mode 100644 index 4dd7bc3d9..000000000 --- a/nemo-physical/src/util/tagged_tree.rs +++ /dev/null @@ -1,115 +0,0 @@ -//! Module containing a data structure for representing trees with node labels. - -use std::fmt::{Debug, Display}; - -/// A tree structure such that every node in the tree has a tag of the given tag type. -#[derive(Clone, Eq, PartialEq)] -pub struct TaggedTree { - /// The tag of the node. - pub tag: Tag, - /// The subtrees below this node. - pub subtrees: Vec>, -} - -impl TaggedTree { - /// Construct a new [`TaggedTree`]. - pub fn tree(tag: Tag, subtrees: Vec>) -> Self { - Self { tag, subtrees } - } - - /// Construct a new [`TaggedTree`] consisting of a single leaf node. - pub fn leaf(tag: Tag) -> Self { - Self::tree(tag, vec![]) - } - - /// Return whether this node is a leaf node. - pub fn is_leaf(&self) -> bool { - self.subtrees.is_empty() - } - - /// Recursive implementation of the function `leaves`. - fn leaves_recursive(tree: &TaggedTree) -> Vec<&Tag> { - let mut result = Vec::<&Tag>::new(); - - if tree.is_leaf() { - result.push(&tree.tag); - } else { - for subtree in &tree.subtrees { - result.extend(Self::leaves_recursive(subtree)); - } - } - - result - } - - /// Return a list of references to the tags of the leaf nodes in the tree. - pub fn leaves(&self) -> Vec<&Tag> { - Self::leaves_recursive(self) - } - - /// Recursive implementation of the function `leaves_mut`. - fn leaves_mut_recursive(tree: &mut TaggedTree) -> Vec<&mut Tag> { - let mut result = Vec::<&mut Tag>::new(); - - if tree.is_leaf() { - result.push(&mut tree.tag); - } else { - for subtree in &mut tree.subtrees { - result.extend(Self::leaves_mut_recursive(subtree)); - } - } - - result - } - - /// Return a list of mutable references to the tags of the leaf nodes in the tree. - pub fn leaves_mut(&mut self) -> Vec<&mut Tag> { - Self::leaves_mut_recursive(self) - } -} - -impl Debug for TaggedTree -where - Tag: Debug, -{ - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.is_leaf() { - return write!(f, "{:?}", self.tag); - } - - write!(f, "{:?}(", self.tag)?; - - for (index, subtree) in self.subtrees.iter().enumerate() { - write!(f, "{subtree:?}")?; - if index < self.subtrees.len() - 1 { - write!(f, ", ")?; - } - } - - write!(f, ")")?; - Ok(()) - } -} - -impl Display for TaggedTree -where - Tag: Display, -{ - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.is_leaf() { - return write!(f, "{}", self.tag); - } - - write!(f, "{}(", self.tag)?; - - for (index, subtree) in self.subtrees.iter().enumerate() { - write!(f, "{subtree}")?; - if index < self.subtrees.len() - 1 { - write!(f, ", ")?; - } - } - - write!(f, ")")?; - Ok(()) - } -}