-
Notifications
You must be signed in to change notification settings - Fork 49
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
please add a weak ref type #65
Comments
Ideally there would be a WeakSet type that automatically removes the thing from the set (this is a common pattern in GCd languages). Don't have the time to work on this, but would accept a PR adding it. |
Weak should be able to implement Hash and Eq |
I was finally playing with this again today. I exposed a function that lets me check how many roots a I doubt you want to expose this as part of the public API and I'm not even sure it's a good way to implement the feature I wanted. Instead, I could add it as an internal part of the API and then make a wrapper around the Perhaps some of these issues would be conceptually easier if there was a dedicated Thoughts? |
I started using this crate for my prolog interpreter (it's great, thank you for making it!).
I'd to make my interpreter do hash consing of the terms. Actually, I already made this change, but since there is no weak version of the
Gc
type, my interpreter now never collects anything. The reason is because theHashSet
I use to store terms has a strong reference so once a term is inserted into my heap, it lives forever. Normally, when implementing hash-consing you store weak references in the hashset.Basically, I want to write code like this:
I tried something similar using
Rc
andWeak
fromstd
(even though cycles would cause issues), but I noticedWeak
doesn't implementHash
andEq
so they can't be used as keys in aHashMap
(and by extension, aHashSet
). I don't know if that is due to the way derefereningWeak
works or what. Perhaps I'll also need a custom collection type. Anyway, do you think that would be an issue here as well?Would a weak version of
Gc
be hard to add? I haven't looked at the code yet, but if it's not too hard I might try adding one.The text was updated successfully, but these errors were encountered: