petgraph icon indicating copy to clipboard operation
petgraph copied to clipboard

[Feature Requirement] To support iterating nodes/edges of given types more efficiently

Open longbinlai opened this issue 3 years ago • 0 comments

Acknowledge

First of all, thank you for providing such a nice tool for playing with graphs in Rust. We actually leverage PetGraph in one of our projects to store the graph structure for doing graph queries. Here is the reference: https://github.com/alibaba/GraphScope/tree/main/research/graph_store

Summary

To scan nodes of given types more efficiently in a labeled graph.

Motivation

In practice, most (nearly all) graphs are labeled graphs. Here, a labeled graph is a graph whose nodes/edges carry some labels to indicate their types. For example, a node of "person" type can connect to another node of "person" type via the "knows" edge. It is of great demand to support such graphs well.

Details

In PetGraph's design, such as, pub type StableDiGraph<N, E, Ix = DefaultIx> = StableGraph<N, E, Directed, Ix>;

N and E can be used to carry the label information. However, while we try to iterate the nodes/edges of given labels, which is very common in practice, we must do something like:

g.neighbors_directed(v, dir)
  .filter(|n| n == label)

This is very inefficient, considering there may be many different types of nodes, and filtering any given type out always requires scanning all types of neighbors.

longbinlai avatar Jun 15 '22 01:06 longbinlai