3 ms·
Doubly-linked list is something you have almost no reason to ever write. Parent field is something where you have a clear hierarchy (it's not really “cyclic”,
by littlestymaar 3y ago
Doubly-linked list is something you have almost no reason to ever write.
Parent field is something where you have a clear hierarchy (it's not really “cyclic”, so it's the perfect use-case for weak references).
When coming from a managed-memory language, this obviously requires some conceptual effort to understand why this is a problem at all and how to deal with it, but when compared to C or C++, the situation is much better in Rust.
- jacobgorm 3y agoAlso, a parent field is something you should be able to infer, e.g, keep a stack of parents as you traverse down a search tree following the child pointers, instead of storing parent pointers in the tree nodes.
- akoboldfrying 3y agoThat's assuming you traverse the tree down from the root each time. Often you do, but there are cases where you don't -- e.g., if your goal is to determine the lowest common ancestor of two given nodes.