References to set of unique values

Hi there. I am currently trying to build a data structure that has two sets of unique values and a third set of a reference to each one and one extra value.

What i've tried so far is using three hashbrown::HashSet's like so

struct MyDatastructure {
   value1: HashSet<Type1>
   value2: HashSet<Type2>
   value3: HashSet<(Type3, &Type1, &Type2)>

The important point is the uniqueness of every element in value1 or value2 and the combination of two such values and a third value.

I've come to notice that this does not work, as when I am inserting into value1 or value2 the HashSet could outgrow it's capacity and then relocate to somewhere else, and the reference would be no longer valid. Is there some nice way to do such data structures?

For any responses or suggestions I would be very grateful.

Thank you
Justus Flügel

Rust doesn't safely support structures like this (search the forum for "self-referencial" to see many examples).


I know that, that's what I've realized as well. I am more looking for alternatives or for example crates that could help with that, or if you have some alternative way that could be possible that would be great as well

1 Like

You could consider using something like

struct MyDatastructure {
   value1: HashSet<Rc<Type1>>
   value2: HashSet<Rc<Type2>>
   value3: HashSet<(Type3, Rc<Type1>, Rc<Type2>)>

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.