Re:Was Rust Worth It?
by jcelerier on Thursday October 26, 2023 @08:35AM
(#38024697)
Maybe for you it's unusual - in my previous work all the apps contained graphs, and I just joined a company where almost all the apps also contain graphs
[ Parent
| on HN ]
Re:Was Rust Worth It?
by underdeserver on Thursday October 26, 2023 @09:12AM
(#38025058)
I don't write Rust, but I never understood why graphs meant you need circular references.
Doesn't it just come down to the question of who owns the node?
If it's a tree, and parents are never removed before children, just make the child owned by the parent and keep a weak reference to the parent.
If it's a general graph, and vertices can exist or not exist regardless of edges, keep a list of them independent of the edges, and keep weak references in the edges.
If it's a graph where a one or a few roots exist, and nodes exist as long as there's a path from a root node to them, that sounds like a classic use case for Rc<>.
Is there a common use case I'm missing?
Things get tricky when you have a valid triangular relationship amongst equal objects. This comes up far more often than you’d expect.
Re:Was Rust Worth It?
by underdeserver on Sunday October 29, 2023 @12:33AM
(#38055823)
Can you give an example?