6 ms·
Doubly-linked list without unsafe code.
by lightgreen 11y ago
Doubly-linked list without unsafe code.
- ben0x539 11y agoA whole GC sounds like a lot of unsafe code!
- lomnakkus 11y agoCertainly, but that's a one-time cost (wrt. code complexity at least).
- steveklabnik 11y agohttp://bluss.github.io/ixlist/target/doc/ixlist/struct.List.html http://bluss.github.io/ixlist/target/doc/ixlist/struct.List.... * Only use of unsafe is an unavoidable use for IterMut.
- SamReidHughes 11y agoThat general technique pushes the problem around, where an implementation error will still result in a use-after-free (where you access a dead/reused array element). This could be fixed by paying for a runtime version check. Also, because it uses a Vec, it doesn't have O(1) performance, either. This could also be fixed by using a different underlying data structure.
- steveklabnik 11y agoYeah, it certainly has weaknesses.
- pcwalton 11y agoWell, that's true in Rust, but there are systems out there that will allow you to prove doubly-linked lists correct. An alternate approach to GC/RC would be to introduce more type system machinery (or to try to encode it in a library) to allow the construction of these data structures safely. (Whether this would be worth the effort is another question, of course.)