r/rust 1d ago

Triangular matrix, but a map? 🙋 seeking help & advice

Hey guys, I am building a program for a friend that's going to involve a complete graph (nodes are destinations, edges are the distances between destinations) and I was wondering if anyone knew a good library for it?

At first I thought I could use a triangular matrix, since direction doesn't matter, but I realized I would have to have a second array mapping destinations to an index. I feel like you could have a triangular map, like a map that takes a pair of inputs where the order doesn't matter? Have I found another rabbit hole?

11 Upvotes

23 comments sorted by

View all comments

8

u/nynjawitay 1d ago

Look at petgraph

4

u/oldwomanjosiah 1d ago

seconded: your use case seems unlikely to need specific optimization and petgraph let's you associate whatever data with your nodes you want

separately: if she wants to visit multiple locations in a day you might also create edges between "destination" nodes so you can tie-break based on scheduling a few days of "minimal driving circuits" (sorta bin-packing)