question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Graph.successors(): add support for ordering the nodes

See original GitHub issue

Graph.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:closed
  • Created 7 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
nymanjenscommented, Jan 9, 2020

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 and ValueGraph. Network support comes later.

Example of how to enable this:

GraphBuilder.directed().incidentEdgeOrder(ElementOrder.stable()).build()

This gives the following guarantees:

  • edges(): Stable order
  • adjacentNodes(node): Connecting edge insertion order
  • predecessors(node): Connecting edge insertion order
  • successors(node): Connecting edge insertion order
  • incidentEdges(node): Edge insertion order
1reaction
nymanjenscommented, May 31, 2021

Fair enough, that sounds like a use case that would indeed benefit from a similar feature on Network

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found