datavis-tech / graph-data-structure

A graph data structure with topological sort and shortest path algorithms.
MIT License
249 stars 46 forks source link

Check if an edge exist or not #46

Closed Symbolk closed 3 years ago

Symbolk commented 3 years ago

Hi, thanks for the nice work!

However, I did not find API to check if any edge exists or not between two nodes, which is one of the common operations, and should not be hard to implement with high performance. Any tips?

curran commented 3 years ago

The way to know if there's an edge from nodeA to nodeB would be someting like:

graph.adjacent(nodeA).find(node => node === nodeB)`

Would you also want to detect the opposite direction as well?

We could conceivably add a new method that does this.

curran commented 3 years ago

I added the method an published as https://github.com/datavis-tech/graph-data-structure/releases/tag/v1.14.0

Symbolk commented 3 years ago

The way to know if there's an edge from nodeA to nodeB would be someting like:

graph.adjacent(nodeA).find(node => node === nodeB)`

Would you also want to detect the opposite direction as well?

We could conceivably add a new method that does this.

Ok, thanks, since this lib creates directed graph by default, checking only directed edge is reasonable.