From 80185c2c448eb1d11e3b254df28a3804b3437c3f Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Wed, 26 Jul 2023 15:43:19 -0400 Subject: [PATCH] Add cost from children to parent --- src/algorithms.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/algorithms.rs b/src/algorithms.rs index a32d090..d5c751a 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -48,6 +48,7 @@ impl EGraph { } // 4. Inline leaf nodes into their parents for (parent, leaf_children) in &parents_to_children { + let additional_cost = leaf_children.iter().map(|child| self.nodes.get(child).unwrap().cost).sum::>(); let parent_node = self.nodes.get_mut(parent).unwrap(); let args = parent_node .children @@ -67,6 +68,7 @@ impl EGraph { .retain(|child| !leaf_children.contains(child)); let new_op = format!("{}({})", parent_node.op, args); parent_node.op = new_op; + parent_node.cost += additional_cost; } } }