-
Notifications
You must be signed in to change notification settings - Fork 164
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
Enhance traversal docs #1375
base: main
Are you sure you want to change the base?
Enhance traversal docs #1375
Conversation
|
Thanks for submitting this! I will try to review it when I can, but again this is a welcome contribution. |
Pull Request Test Coverage Report for Build 13047597904Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me with the caveat that I think for Python docstrings we should focus on the methods that highlight BFS
/DFS
only. I'd drop the iterator details
end while | ||
|
||
If an exception is raised inside the callback function, the graph traversal | ||
def BFSIterator(G, I, F): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Python I think it makes more sense to talk about BFS
than BFSIterator
. I'd rewrite it to keep the old signature BFS(G, s)
@@ -1565,38 +1633,68 @@ def tree_edge(self, edge): | |||
|
|||
@_rustworkx_dispatch | |||
def dfs_search(graph, source, visitor): | |||
"""Depth-first traversal of a directed/undirected graph. | |||
"""Iterative depth-first traversal of a directed/undirected graph. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have a recursive DFS with something like https://crates.io/crates/recursive these days, so I am not opposed to saying this.
With that in mind, DFS order is implementation dependent and even the order we iterate edges is not promised to be stable so it is what it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the Iterative
prefix from the rustworkx-core
since it made sense to me to differentiate this method from the DFS algorithm which has a single source vertex.
I didn't know about DFS (the CLRS ref you sent me was helpful!) but my friends who do know (both the algo and of CLRS) were confused a bit by how several source vertices are incorporated.
If the implementation detail of how several source vertices are incorporated into DFS is not guaranteed, the docs should probably mention that as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will double check Georgios’ implementation in the source code and check.
I myself forgot the specifics, either the user passes it as an input or we pick an arbitrary node I think
color[u] := BLACK finish vertex u | ||
|
||
If an exception is raised inside the callback function, the graph traversal | ||
def DFSIterator(G, I, F): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment from BFS
color[s] = GRAY | ||
time += 1 | ||
F.Discover(s, time) | ||
Q = [s] # LIFO vertex queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call it a stack
This PR fixes #1361.
It add some elaboration to the traversal BFS and DFS functions, mainly with a more concrete pseudo-code.
I also fixed small doc errors in betweenness function's docstrings.
In the issue I also suggested doing a face-lift to the dijkstra_search. I can add this in to this PR in the style of the other docstrings changes I'm proposing If you'd like.
nox -e docs
andcargo doc
to see that the result is good.