The popular gc
crate doesn't support any weak form of WeakSet
. Is there any crate with this functionality? Or is there a weak vec/set for std::sync::Arc
?
I need this for implementing internated strings.
The popular gc
crate doesn't support any weak form of WeakSet
. Is there any crate with this functionality? Or is there a weak vec/set for std::sync::Arc
?
I need this for implementing internated strings.
So what you actually need is reference counted strings where you can look up the set of existing strings to avoid duplication?
Yep. It doesn't need to be mark-n-sweep algorithm necessarily.
You can have a hash set that contains an std::rc::Weak
to a thing containing the string and a reference back to the set. Then make the thing remove itself on drop.
Is there a simple example? I don't think I can override the Drop
for an Arc
/Weak
...
The Drop goes on the struct inside the Arc, not on the Arc itself.
it's interned, not internated.
and you don't need Rc's for it, I managed to make an implementation using only a bimap.
but there's already a very popular crate for string interning: string_interner - Rust
That could be useful, but I need a custom string type that doesn't store its characters with &str
or String
.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.