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

Add examples #5

Open
djmitche opened this issue Jun 22, 2021 · 3 comments
Open

Add examples #5

djmitche opened this issue Jun 22, 2021 · 3 comments

Comments

@djmitche
Copy link

HI there! I figured I'd take a shot at building a doubly-linked list with static-rc, and it turned out to be pretty difficult. The main difficulty is in constructing reference cycles, as it's not possible to have more than two pointers to any list element.

Is there an example of this, or any other similar data structure? Could that be added to the docs?

@djmitche
Copy link
Author

My attempt is here

@matthieu-m
Copy link
Owner

Yes, I tried too and it's definitely non-trivial :)

You can see my attempts at https://github.com/matthieu-m/ghost-collections, you'll see there are 2 linked-lists:

  1. linked_list.rs which works with 1/2 pointers.
  2. tripod_list.rs which works with 1/3 pointers, and has each node storing a pointer to itself (the tripod) which can be temporarily deployed to "anchor" the node to the stack.

The latter was definitely easier, but first of all it relies on the experimental lift feature which isn't... great, and second it has the obvious disadvantage of requiring an extra pointer per Node, which isn't... great.

Maybe I should revise the README.txt to indicate that actually managing to create a LinkedList with the footprint & performance of raw-pointers with static-rc is non-trivial; or at least, that some operations are really hard to get.


One possibility for the examples would be linking to ghost-collections, but it combines both StaticRc and GhostCell so that may be a bit too complicated.

Please let me know how decipherable you find ghost-collections and whether you think it's a good example or we'd be better off with something using regular RefCell instead to avoid mixing novelties.

@djmitche
Copy link
Author

I read the paper on GhostCell, so I may not be an unbiased sample, but I do think that's helpful. It may be worth including something brief about GhostCell -- basically, it can be treated as a "regular" Cell and the token stuff ignored, as far as understanding the StaticRc usage goes.

It may also be worth elaborating on the lift operation some more. I had a look at the forum post about it, but it wasn't enough for me to understand the intent.

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

2 participants