matthieu-m/static-rc

Add examples

Opened this issue · 3 comments

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?

My attempt is here

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.

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.