Skip to content

basic version of eval function#3

Merged
Modertool999 merged 2 commits into
mainfrom
graph-eval
Jul 3, 2026
Merged

basic version of eval function#3
Modertool999 merged 2 commits into
mainfrom
graph-eval

Conversation

@Modertool999

Copy link
Copy Markdown
Collaborator

No description provided.

@sampsyo sampsyo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome; seems like a great start. My recommendation for the next micro-step here would be to set up some tests so you can "lock in" the current behavior of this evaluator before adding features/performance/etc.

Comment thread src/graph/eval.rs Outdated
use super::{AigGraph, NodeId};

impl AigGraph {
pub fn eval(&self, id: NodeId, input_values: &HashMap<NodeId, usize>) -> usize {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to set up for future changes, I recommend using a couple of type aliases here:

type Value = usize;
type Env = HashMap<NodeId, Value>;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread src/graph/eval.rs Outdated
Comment on lines +7 to +11
match id {
id if id.is_false() => 0,
id if id.is_true() => 1,
id if id.is_inverted() => 1 - (self.eval(id.regular(), input_values)),
id => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand the temptation to use match here, I think in this case, I'm not sure it successfully makes things much more readable than an if ... else if ... cascade (because we're not actually matching any patterns). I suppose either way can work, but you might find that the latter parts of this function (where you check for properties of the node itself) would be a little easier (and less indented) with a normal cascade and early returns.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do! I was pretty torn between using match and if else, and I do agree that if else would prob be better here, the match wasn't as "clean" as I thought it would be

@sampsyo sampsyo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I think it did end up being a little more readable with the else if cascade rather than match.

I say go ahead and merge this! Maybe testing is the next step, and that could go in a separate PR?

@Modertool999 Modertool999 merged commit 037df18 into main Jul 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants