I have a graph defined using Rust's petgraph crate. The node's weight type is String, denoting a node's "name". Is there a way to obtain the node index knowing only the node's weight (i.e. its name)? The crate's documentation does not seem to provide any such function.
Or do I need to maintain a name-to-index mapping myself on the side?
I just encountered the same issue. I came up with a (not very pretty, but functional) solution:
It's better to keep your own HashMap if you have a lot of nodes, but this was good enough for me.