I would like to create an unweighted, undirected graph with string nodes in Rust. I've been trying to use petgraph and the from_edges construction method provided on UnGraph, but I am unable to do so because &str is not a valid NodeIndex. Is there an easier way to do this?
How do I make an unweighted, undirected graph with string nodes in Rust?
487 Views Asked by Alexander Brassel At
1
You can use a
HashMapin where the keys are the nodes, and the values are aVecof nodes connected to the key one. For convenience useStringas the primary type for Nodes. Also notice that the graph being undirected just means that you would need to add both nodes to the adjacent list. In the example fashion: