-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
can i find the leader/source vertex of a directed acyclic graph ? #166
Comments
A more wide application for implementing this would be to merge two graphs g.addEdge(vertex v, <source vertex of DAG> doing this will merge DAG into graph g on its vertex v. UPD: first you must implement
|
To all those who might be looking for a solution: func FindSource[K comparable, T any](g graph.Graph[K, T]) ([]K, error) {
if !g.Traits().IsDirected {
return nil, fmt.Errorf("cannot find source of a non-DAG graph ")
}
predecessorMap, err := g.PredecessorMap()
if err != nil {
return nil, fmt.Errorf("failed to get predecessor map: %w", err)
}
var sources []K
for vertex, predecessors := range predecessorMap {
if len(predecessors) == 0 {
sources = append(sources, vertex)
}
}
return sources, nil
} |
Hi, thanks for the late response! Using |
Yes. I was wondering will there be a function |
@AkashKumar7902 Yes, that sounds reasonable. Feel free to submit a PR! |
No description provided.
The text was updated successfully, but these errors were encountered: