Hacker News new | ask | show | jobs
by amelius 3413 days ago
I wish they had a chapter covering how to efficiently implement graph algorithms without ending up in a struggle with the borrow checker.
2 comments

Have you read this one yet? http://cglab.ca/~abeinges/blah/too-many-lists/book/

It touches on the issues you are implying.

A possibility is to use a different representation for graphs, such as adjacency matrices, which are much easier to work with the borrow checker.

Or just use RefCell, deferring the borrow checking until runtime.

Another strategy could be to give every node an explicit ID, and then have a mapping ID -> node. Every else you just refer to the nodes by their IDs.