3 ms·
> Things like dynamically updated graphs are nearly impossible to write in Rust Just curious, have you tried to handroll these, or have you used libraries? (eg.
by TwentyPosts 3y ago
> Things like dynamically updated graphs are nearly impossible to write in Rust
Just curious, have you tried to handroll these, or have you used libraries? (eg. petgraph, though I don't know if it'd suit your usecases.)
I'm a Rust connoisseur, but I'd agree with 'nearly impossible to write', which is why I'd (first of all) try to grab a library, assuming I'm doing anything complicated with graphs. If it's very simple and specific, I'd try to go through the list of possible graph representations (eg. adjacency lists), and pick a suitable one, but never store nodes directly, rather store indices (while the nodes are stored in some sort of vector).
- atemerev 3y agoThis is where I ended up (adjacency lists), but yes, it was quite unintuitive (because you need some central entity to manage adjacency lists, and that idea somehow eluded me for a long time). Rust really doesn't like updating references (and anything non-hierarchical in general).
- pimeys 3y agoThe index/vector strategy is also perfect for basic trees, if you need to have cyclic dependencies between the nodes, and as a cherry on top it serializes super well. Requires a bit of boilerplate in the beginning, but pays off when actually needing to work with your data.
- cozzyd 3y agoBefore you know it, you'll have implemented pointers, a heap and some equivalent of malloc/free.