Skip to content

Commit

Permalink
nits and use saturating_add for cost
Browse files Browse the repository at this point in the history
  • Loading branch information
yihozhang committed Aug 17, 2023
1 parent f2fe645 commit 9317372
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
17 changes: 0 additions & 17 deletions src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,4 @@ impl<'a> Extractor<'a> {
}
}
}

pub(crate) fn value_cost(
&self,
sort: &ArcSort,
value: &Value,
termdag: &mut TermDag, // it does not make a lot sense to pass termdag since
// we are not returning any term. But to get the cost of
// we have to construct the term first.
) -> Option<usize> {
if sort.is_eq_sort() {
let id = self.egraph.find(Id::from(value.bits as usize));
let (cost, _node) = &self.costs.get(&id)?;
Some(*cost)
} else {
Some(sort.extract_expr(self.egraph, *value, self, termdag)?.0)
}
}
}
4 changes: 2 additions & 2 deletions src/sort/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ impl Sort for SetSort {
) -> Option<(Cost, Expr)> {
let set = ValueSet::load(self, &value);
let mut expr = Expr::call("set-empty", []);
let mut cost = 0;
let mut cost = 0usize;
for e in set.iter().rev() {
let e = extractor.find_best(*e, termdag, &self.element)?;
cost += e.0;
cost = cost.saturating_add(e.0);
expr = Expr::call("set-insert", [expr, termdag.term_to_expr(&e.1)])
}
Some((cost, expr))
Expand Down

0 comments on commit 9317372

Please sign in to comment.