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

feat: add topological sorting #307

Merged
merged 3 commits into from
Apr 9, 2022

Conversation

fffzlfk
Copy link
Contributor

@fffzlfk fffzlfk commented Apr 6, 2022

No description provided.

@erfan-khadem
Copy link
Contributor

Hi!
Based on this comment, it was decided we can have some code (I implemented it in #294, not merged yet) that converts between BTreeMap representation and a Vec based one.

As I am reading your code, it would be more performant, smaller, and more readable if you change it to use a Vec based (compressed) adjacency matrix representation.

Even if (for understandable reasons) you don't want to do it that way, I have a suggestion:
representing the list of adjacent vertices for each vertex v in the graph as a separate BTreeMap is kind of overkill. You can easily get more performance by replacing BTreeMap<V, BTreeMap ...> with BTreeMap<V, Vec<(V, E)>>

One minor thing: You can remove Debug trait bound for your vertex type.

@fffzlfk
Copy link
Contributor Author

fffzlfk commented Apr 7, 2022

Hi! Based on this comment, it was decided we can have some code (I implemented it in #294, not merged yet) that converts between BTreeMap representation and a Vec based one.

As I am reading your code, it would be more performant, smaller, and more readable if you change it to use a Vec based (compressed) adjacency matrix representation.

Even if (for understandable reasons) you don't want to do it that way, I have a suggestion: representing the list of adjacent vertices for each vertex v in the graph as a separate BTreeMap is kind of overkill. You can easily get more performance by replacing BTreeMap<V, BTreeMap ...> with BTreeMap<V, Vec<(V, E)>>

One minor thing: You can remove Debug trait bound for your vertex type.

Thanks for the review, I have done as you suggested

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@siriak siriak merged commit bbc60e4 into TheAlgorithms:master Apr 9, 2022
@fffzlfk fffzlfk deleted the topological_sorting branch April 9, 2022 16:32
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.

None yet

3 participants