Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double linked list #57

Closed
stereobooster opened this issue Oct 6, 2016 · 3 comments
Closed

Double linked list #57

stereobooster opened this issue Oct 6, 2016 · 3 comments

Comments

@stereobooster
Copy link

First of all: thank a lot. I enjoyed reading this manual.

I cheated a bit and googled for "rust double linked list". There is seems to be solution to problem of who is owning who: stackoverflow.

Second link it to your website e.g. cglab.ca/~abeinges/blah/too-many-lists/book/

@stereobooster
Copy link
Author

I'm thinking about trying to use Weak for connection between nodes in one direction and Rc in opposite direction. It should remove cycles as far as I understand it.

@Manishearth
Copy link
Collaborator

Weak lets you implement it safely. I'm not sure what you're proposing? THere already is an impl of a DLL here. There's also one in the stdlib.

@stereobooster
Copy link
Author

stereobooster commented Oct 16, 2016

It seems I miss something. Trivial reference counting can't handle cycles. And DLL is the minimum possible cycle (graph of two objects). Right? And Weak references do not count when determining if the inner value should be dropped.

UPD: Yes I see

impl<T> Drop for List<T> {
    fn drop(&mut self) {
        while self.pop_front().is_some() {}
    }
}

doing the trick. I just thought that Weak is good fit for the case and want to give it a try

@Gankra Gankra closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants