Graph.successors(): add support for ordering the nodes
See original GitHub issueGraph.successors()
returns nodes in an undetermined order which makes it difficult to use Graph
as a rooted tree where the ordering of the children is important (e.g. something similar to XML) with a schema that orders some elements).
I have the following workaround but it seems expensive (although for small trees I suppose it doesn’t really matter):
fun <N> Graph<N>.children(node: N): Set<N> {
return nodes().toMutableSet().apply { retainAll(successors(node)) }
}
Can supported be added to specify the order of nodes returned by successors()
?
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (11 by maintainers)
Top Results From Across the Web
python - Directed graph nodes: Keep track of successors and ...
predecessors.add(node_1) and thus lead to an infinite loop. Generating one of the two attributes on the fly (node for node in all_nodes ......
Read more >Directed graph traversal, orderings and applications to data ...
This algorithm adds a node to the order list when its traversal is fully finished; that is, when all its outgoing edges have...
Read more >Graph (Guava: Google Core Libraries for Java 20.0 API)
GraphBuilder.build() returns an instance of MutableGraph , which is a subtype of Graph that provides methods for adding and removing nodes and edges....
Read more >DiGraph.successors — NetworkX 2.8.8 documentation
A successor of n is a node m such that there exists a directed edge from n to m ... If n is...
Read more >graphlib — Functionality to operate with graph-like structures ...
A topological order is a linear ordering of the vertices in a graph such that for ... Additional nodes can be added to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, I’m a also a maintainer of this library and just added the possibility of returning successors in insertion order. This should be included in the next Guava release for
Graph
andValueGraph
.Network
support comes later.Example of how to enable this:
This gives the following guarantees:
edges()
: Stable orderadjacentNodes(node)
: Connecting edge insertion orderpredecessors(node)
: Connecting edge insertion ordersuccessors(node)
: Connecting edge insertion orderincidentEdges(node)
: Edge insertion orderFair enough, that sounds like a use case that would indeed benefit from a similar feature on Network