Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find() with a closure #31

Closed
yegor256 opened this issue Nov 7, 2022 · 12 comments
Closed

find() with a closure #31

yegor256 opened this issue Nov 7, 2022 · 12 comments

Comments

@yegor256
Copy link
Member

yegor256 commented Nov 7, 2022

This is what I would like to be able to do with Sodg.find() function:

use sodg::Sodg;
let mut g = Sodg::empty();
g.add(0).unwrap();
g.add(1).unwrap();
g.bind(0, 1, "foo").unwrap();
let v = g.find(0, "bar", |v, a| "foo").unwrap();
assert_eq!(1, v);

The closure that I provided to find function expects two parameters: 1) the ID of the vertex where finding algorithm stopped because edge "foo" is absent (v=0), 2) the name of the edge not found (a="bar"). The closure returns an alternative name of the edge and the search algorithm continues from it.

@yegor256
Copy link
Member Author

yegor256 commented Nov 7, 2022

@UARTman can you please help?

@UARTman
Copy link
Contributor

UARTman commented Nov 7, 2022

Sure. Let's check if I understand correctly what you want it to do.

It checks for "bar" in children, doesn't find it, then goes through the children, calling the closure on every one, until it finds "bar". Then it uses that edge and goes further.

@yegor256
Copy link
Member Author

yegor256 commented Nov 7, 2022

@UARTman not exactly. It checks for "bar" in children, doesn't find it. Then, it calls the closure giving it itself (0) and the name of the missing children ("bar"). The closure returns "foo". It finds "foo" in children and continues.

I made a mistake in the original description of the ticket. Now fixed.

@yegor256
Copy link
Member Author

yegor256 commented Nov 7, 2022

@UARTman let's make it even more convenient. Let the closure accept three params: vertex ID, the head of the label, and the tail of the label. Say, the label is "a/bc.de". Here "a" is the head, while "bc.de" is the tail. If the label is "foo" -- its tail is "" (empty string).

@yegor256
Copy link
Member Author

yegor256 commented Nov 9, 2022

@UARTman any progress?

@UARTman
Copy link
Contributor

UARTman commented Nov 9, 2022

I have an implementation that seems to work in a separate function find_with_closure. Should I just replace find with the new function or leave find as-is?

After we figure out this, I'll have to improve a docstring a bit, and then it'll be ready for merge.

@yegor256
Copy link
Member Author

yegor256 commented Nov 9, 2022

@UARTman let's merge find_with_closure first

@yegor256
Copy link
Member Author

@UARTman any good?

@UARTman
Copy link
Contributor

UARTman commented Nov 11, 2022

I'll send a pull request tomorrow.

UARTman added a commit to UARTman/sodg that referenced this issue Nov 12, 2022
UARTman added a commit to UARTman/sodg that referenced this issue Nov 13, 2022
@yegor256
Copy link
Member Author

@rultor release, tag is 0.0.12

@rultor
Copy link
Contributor

rultor commented Nov 18, 2022

@rultor release, tag is 0.0.12

@yegor256 OK, I will release it now. Please check the progress here

@rultor
Copy link
Contributor

rultor commented Nov 18, 2022

@rultor release, tag is 0.0.12

@yegor256 Done! FYI, the full log is here (took me 17min)

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

No branches or pull requests

3 participants